Notice there is no parenthesis before fn in the list definition.
So, it's equivalent to calling ('fn 1 3), ie. calling the Symbol
implementation of AFn, which searches the sym in the first argument and
returns the second arguments in can't find it. That's why it's returning 3.
--
You received t
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 wrote:
> Didn't try, but shoudn't (def alist `(1 ~(fn [x y] (+ x y be better?
For that method, you need a back-quote ` (used in macro definition) in front
of the 1, not a single quote ' (used to make a form data instead of code).
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googl
this is because in order to use ~ to evaluate the fn, you need to use the
backtick ` instead of the single quote '
Il giorno 13/lug/2011 00.34, "Paul Meehan" ha scritto:
>
> Sorry to repoen the discussion, but I got this:
>
>
> => (def alist '(1 ~(fn [x y](+ x y
> #'user/alist
>
> => (apply (s
Sorry to repoen the discussion, but I got this:
=> (def alist '(1 ~(fn [x y](+ x y
#'user/alist
=> (apply (second alist) '(1 3))
#clojure.lang.Cons cannot be cast to clojure.lang.IFn
(NO_SOURCE_FILE:0)>
On 07/12/2011 23:13, Benny Tsai wrote:
Nice, yes, that works just as well :)
On Tue
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? The
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
>
>> alist is missing parens around the fn, so it's really a
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
> 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.
Hi Paul,
I posted an answer to your question in the "monads > macros" discussion.
--
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
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 defi
Hi
I was wondering if anyone could shed some light on the
following code:
(def alist '(1 fn [x y](+ x y)))
(apply (second alist) '(1 3))
The result at REPL is 3 i.e. the second element of '(1 3).
Should the result not be 4 i.e. the result of applying the
arguments 1 and 3 to the anonymous fu
Hi
I was wondering if anyone could shed some light on the
following code:
(def alist '(1 fn [x y](+ x y)))
(apply (second alist) '(1 3))
The result at REPL is 3 i.e. the second element of '(1 3).
Should the result not be 4 i.e. the result of applying the
arguments 1 and 3 to the anonymous
12 matches
Mail list logo