> user> (def my-func (list + 1 2))
> #'user/my-func
> user> (my-func)

A list is not a function. Expanded: ((list + 1 2)) The first item in
the outer list is a list, it is not a function. So to invoke the
function you need to get it using first. Eval call on a list is
evaluating a list, and the first item is a function so yup that works.
It was bad (confusing) advice from me to store it like this really.
You could just as easily used something like (let [my-fun {:fn
+, :args [1 2]}] (apply (:fn my-fun) (:args my-fun))) The list
approach is slightly more compact in that you can use eval and it
'looks' more lispy? Just a note, apply here isn't doing anything
magical it is just unpacking the arguments to give (+ 1 2).


> user> (def my-func (list + 1 2))
> #'user/my-func
> user> (eval my-func)
> 3

> I don't really understand how:
> user>(my-func) is NOT eval on my-func in the REPL.
> My understanding is
> the first item in the list is treated as a function, with the rest of
> the list passed as arguments. Wouldn't the REPL just be calling eval
> internally on everything you type in?

Yes they are both evaluated, but they are different expressions:
((+ 1 2))
vs (+ 1 2)


Regards,
Tim.

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