Re: Why ('f 1) does deliver nil?

2019-10-26 Thread Johannes
Thank you for the explanation; until now I associated this behavior only to 
keywords not not symbols.

Johannes

Am Samstag, 26. Oktober 2019 19:12:11 UTC+2 schrieb Andy Fingerhut:
>
> Both symbols and keywords, when placed inside of an expression in the 
> first position, e.g. (:my-keyword my-map), or ('some-symbol my-map), behave 
> as functions that "look themselves up" in the map that is the first 
> argument, and if that symbol or keyword is a key in that map, the 
> associated value is returned from the expression.  This is most often used 
> for keywords, but it does also work for symbols, which is what is happening 
> in your expression.  The number `1` is not a map, and both this kind of 
> lookup expression, as well as the function `get`, have always returned nil 
> when the thing-to-be-looked-up-in is not a map or set (or anything else 
> that implements the appropriate lookup interface methods being used in the 
> Java implementation under the covers there).
>
> Some other examples of similar behavior:
>
> $ clj
> Clojure 1.10.1
> user=> ('f 1)
> nil
> user=> ('f 1 :not-found)
> :not-found
> user=> ('f {'f 17 :bar 8})
> 17
> user=> ('f {:bar 8} :not-found-value)
> :not-found-value
> user=> (get {'f 17 :bar 8} 'f)
> 17
> user=> (get 1 'f)
> nil
> user=> (get 1 'f :not-found)
> :not-found
>
> Andy
>
>
>
> On Sat, Oct 26, 2019 at 10:05 AM Johannes  > wrote:
>
>> ... instead of an exception?
>>
>> Can anyone explain it to me?
>>
>> Johannes
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clo...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clo...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/clojure/f2007954-107c-4918-bf0a-6bfd8040ba39%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/8d0613d6-a084-4035-9208-226ed8a911d9%40googlegroups.com.


Re: Why ('f 1) does deliver nil?

2019-10-26 Thread Faiz Ahmed Mushtak Halde
Well, Symbols implement the IFn and if you look at the invoke method, the 
arg passed to it is considered to be a map (I guess more like an 
environment it expects in which it will try to look for the symbol)

Anyways, since you've passed in a number, the look up in RT.getFrom leads 
to a null hence the nil

('f1  {'f1  3}) returns 3 FYI  and ('f 1 'not-found) returns 'not-found

On Saturday, October 26, 2019 at 10:35:25 PM UTC+5:30, Johannes wrote:
>
> ... instead of an exception?
>
> Can anyone explain it to me?
>
> Johannes
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/f4fdcc4b-0145-49de-acec-5c2d815bcaa1%40googlegroups.com.


Re: Why ('f 1) does deliver nil?

2019-10-26 Thread Andy Fingerhut
Both symbols and keywords, when placed inside of an expression in the first
position, e.g. (:my-keyword my-map), or ('some-symbol my-map), behave as
functions that "look themselves up" in the map that is the first argument,
and if that symbol or keyword is a key in that map, the associated value is
returned from the expression.  This is most often used for keywords, but it
does also work for symbols, which is what is happening in your expression.
The number `1` is not a map, and both this kind of lookup expression, as
well as the function `get`, have always returned nil when the
thing-to-be-looked-up-in is not a map or set (or anything else that
implements the appropriate lookup interface methods being used in the Java
implementation under the covers there).

Some other examples of similar behavior:

$ clj
Clojure 1.10.1
user=> ('f 1)
nil
user=> ('f 1 :not-found)
:not-found
user=> ('f {'f 17 :bar 8})
17
user=> ('f {:bar 8} :not-found-value)
:not-found-value
user=> (get {'f 17 :bar 8} 'f)
17
user=> (get 1 'f)
nil
user=> (get 1 'f :not-found)
:not-found

Andy



On Sat, Oct 26, 2019 at 10:05 AM Johannes  wrote:

> ... instead of an exception?
>
> Can anyone explain it to me?
>
> Johannes
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/clojure/f2007954-107c-4918-bf0a-6bfd8040ba39%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/CAKvLtDYiLJVXxCUTSsaHZXOTAzk4pYGk2%3DJ09Ac2MkYS8aXO5A%40mail.gmail.com.


Why ('f 1) does deliver nil?

2019-10-26 Thread Johannes
... instead of an exception?

Can anyone explain it to me?

Johannes

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/f2007954-107c-4918-bf0a-6bfd8040ba39%40googlegroups.com.


Why ('f 1) does deliver nil?

2019-10-26 Thread Johannes
... instead of an exception?

Can anyone explain it to me?

Johannes

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/e572919f-3a44-4f1b-8120-06ccc98c2be0%40googlegroups.com.