This happens because a Symbol is a "function that looks itself up in its 
argument" much like Keywords do:

user=> ('a {'a 2 'b 3})
2
user=> ('b {'a 2 'b 3})
3
user=> ('b 42)
nil

And the two argument version provides a default value to return if the symbol 
is not found:

user=> ('c {'a 2 'b 3} ::not-found)
:user/not-found
user=> ('c "not a map" ::not-found)
:user/not-found

Sean

On Mar 21, 2014, at 4:44 PM, John Mastro <john.b.mas...@gmail.com> wrote:

> 
> On Fri, Mar 21, 2014 at 3:55 PM, Andy Smith <the4thamig...@googlemail.com> 
> wrote:
> > I came across the following issue when doing problem 
> >
> > user=> (let [f '(+ 1 1)] (apply (first f) (rest f)))
> > 1
> 
> That's interesting. It seems it's the last form in the list that's being
> returned, and it doesn't matter what function you apply
> 
> (apply '+ '(2 1))   ;=> 1
> (apply '+ '(1 2))   ;=> 2
> (apply 'map '(2 1)) ;=> 1
> 
> I don't have any immediate thoughts on why it behaves like that, though
> I'm sure there's a reason (?).
> 
> > I could use eval but eval is bad (apparently)...
> 
> You could use clojure.core/resolve instead, I think that should be safe.
> 
> (let [f '(+ 1 1)]
>   (apply (resolve (first f) (rest f))))
> ;=> 2

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to