A quoted symbol is just a literal "symbol" typed object. These symbols
act as functions where they evaluate like this:
('x 1) => (get 1 'x) - look itself up in its argument
('x 1 2) => (get 1 'x 2) - look itself up in its argument with a
not-found value.

So, in your example:

(bar '(foo 1 2)) tries to run ('foo 1 2). 'foo can't find itself in
the "map" 1 (because it's not a map), so it returns the default value
provided (in this case: 2).

On Fri, Jun 8, 2012 at 2:23 AM, Alex Shabanov <avshaba...@gmail.com> wrote:
> Oh, I see. This is because of the reader that interprets symbols from the
> quoted forms in different way it does for the unquoted ones (and this
> feature still strikes me as odd).
> To make matters more complicated the quoted symbols seems to have some
> meanings as functions for the clojure, since ('foo 1) -> nil, ('foo 1 2) ->
> 2, ('foo 1 2 3 4) -> arity exception.
>
> четверг, 7 июня 2012 г., 20:05:43 UTC+4 пользователь Bronsa написал:
>>
>> you' are calling (apply 'foo '(1 2)), what you want is (apply foo '(1 2))
>> just call bar as
>> (bar (list foo 1 2))
>>
>> 2012/6/7 Alex Shabanov <avshaba...@gmail.com>
>>>
>>> I'm curious why the following form evaluates to 2:
>>>
>>> (defn foo [& more]
>>>   (println "foo(" more " )"))
>>>
>>> (defn bar [v]
>>>   (apply (first v) (rest v)))
>>>
>>> (bar '(foo 1 2))
>>>
>>> If the form (bar '(foo 1 2)) extended to, say, (bar '(foo 1 2 3 4)) the
>>> arity exception will be thrown.
>>> The behavior can be reproduced after picking another names for foo and/or
>>> bar functions.
>>>
>>> --
>>> 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 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 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

Reply via email to