Re: Understanding the quoting of a symbol in a list

2012-01-03 Thread Bill Caputo
On Tue, Jan 3, 2012 at 2:11 PM, JuanManuel Gimeno Illa
 wrote:
> I'm not 100% sure but this is a side effect of the property that symbols can
> be used as functions that find themselves on maps.

Thanks Juan Manuel - that's the thing I was missing (and thanks for
the source link).


bill

-- 
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


Re: Understanding the quoting of a symbol in a list

2012-01-03 Thread JuanManuel Gimeno Illa
I'm not 100% sure but this is a side effect of the property that symbols 
can be used as functions that find themselves on maps.

For instance:

(def m {'a 1 'b 2 'c 3})
('a m)
;=> 1
('b m)
;=> 2

and, when the symbols is not found, we have:

('d m)
;=> nilurn
('d m :nono)
;=> :nono

So a symbol is a function with one or two parameters, the first one the map 
to find itself too and the second, the value to return if not found.

In your example 1 is the supposed map (and 'foo is never found on it) and 2 
is the default value to use.

If you want to read the implementation is in 
clojure.lang.Symbol
.

Juan Manuel

-- 
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

Re: Understanding the quoting of a symbol in a list

2012-01-03 Thread nchurch
If I could hazard a guess, it has to do with symbol lookup in maps.
Try the following:

('foo {'foo 1})

('foo {'bloo 1} 4)

when you do ('foo 1), it can't find foo in 1 (because it isn't there,
and 1 isn't even a map), so it returns nil.  If you do ('foo 1 2),
you've just provided a default value, which it dutifully returns.

It's interesting that symbols don't care whether they are passed maps
or notfun fact!


On Jan 3, 2:47 pm, Bill Caputo  wrote:
> Hi All,
>
> So, I've been doing some experimentation in order to better understand
> the reader, and I can't figure out why I get the following results for
> these four calls:
>
> => ('foo)        ; ((quote foo))
> java.lang.IllegalArgumentException: Wrong number of args (0) passed
> to: Symbol (NO_SOURCE_FILE:0)
>
> => ('foo 1)     ; ((quote foo) 1)
> nil
>
> => ('foo 1 2)   ; ((quote foo) 1 2)
> 2
>
> => ('foo 1 2 3)
> java.lang.IllegalArgumentException: Wrong number of args (3) passed
> to: Symbol (NO_SOURCE_FILE:0)
>
> What I expected is that either foo would be invoked (and so I'd see an
> error because it didn't exist) *or* I'd get a list ala (foo 1 2)
>  - further, I can't understand why I get "nil" for an arity of 1 but
> "2" for an arity of two).
>
> Anyone have an explanation? I'm off to find the impl for "Symbol" and
> see if I can figure out how it is being invoked here...
>
> Thanks,
> Bill

-- 
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


Understanding the quoting of a symbol in a list

2012-01-03 Thread Bill Caputo
Hi All,

So, I've been doing some experimentation in order to better understand
the reader, and I can't figure out why I get the following results for
these four calls:

=> ('foo); ((quote foo))
java.lang.IllegalArgumentException: Wrong number of args (0) passed
to: Symbol (NO_SOURCE_FILE:0)

=> ('foo 1) ; ((quote foo) 1)
nil

=> ('foo 1 2)   ; ((quote foo) 1 2)
2

=> ('foo 1 2 3)
java.lang.IllegalArgumentException: Wrong number of args (3) passed
to: Symbol (NO_SOURCE_FILE:0)

What I expected is that either foo would be invoked (and so I'd see an
error because it didn't exist) *or* I'd get a list ala (foo 1 2)
 - further, I can't understand why I get "nil" for an arity of 1 but
"2" for an arity of two).

Anyone have an explanation? I'm off to find the impl for "Symbol" and
see if I can figure out how it is being invoked here...

Thanks,
Bill

-- 
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