If you use vectors instead of lists, you can avoid quoting altogether:

user> (def alist [1 (fn [x y] (+ x y))])
#'user/alist
user> (apply (second alist) [1 3])
4

Regards,
Stuart

On 13 July 2011 08:09, Joop Kiefte <iko...@gmail.com> 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.t...@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 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