Cheers guys - still getting to grips with Clojure, but
getting there.
On 07/12/2011 23:13, Benny Tsai wrote:
Nice, yes, that works just as well :)
On Tuesday, July 12, 2011 4:09:09 PM UTC-6, LaPingvino wrote:
Didn't try, but shoudn't (def alist `(1 ~(fn [x y] (+
x y)))) be better? Then you don't need the eval :)
2011/7/12 Benny Tsai <benny...@gmail.com>
alist is missing parens around the fn, so it's
really a list of 4 elements like so:
(1, fn, [x y], (+ x y))
So (second alist) returns just the symbol 'fn.
And when you apply a Symbol to a list, the result
is the last item in the list (not sure why).
To do what you want, alist should be defined like
this:
(def alist '(1 (fn [x y] (+ x y))))
Also, it seems that the definition of the function
needs to be eval'ed first to become an apply-able
function. The following returns 4 in my REPL:
(apply (eval (second alist)) '(1 3))
--
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
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
<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