On Sat, Apr 18, 2009 at 2:52 AM, Michael Hunger wrote:
>
> I tried to use an anonymous function in map but it didn't work.
>
> user=> (map #(%) '(1 2 3))
> java.lang.ClassCastException: java.lang.Integer cannot be cast to
> clojure.lang.IFn
>
> but with a normal anonymous function it works as ex
Hi,
Am 18.04.2009 um 14:32 schrieb Michael Hunger:
that also happens with #((+ % 1))
#(%) is equivalent to (fn [x] (x)). So giving an integer as argument
will basically to call an integer => *BOOM*. As you correctly noted.
#((+ % 1)) will be transformed to (fn [x] ((+ x 1))) and again you
wi
2009/4/18 Michael Hunger
>
> I tried to use an anonymous function in map but it didn't work.
>
> user=> (map #(%) '(1 2 3))
> java.lang.ClassCastException: java.lang.Integer cannot be cast to
> clojure.lang.IFn
>
> but with a normal anonymous function it works as expected:
>
> user=> (map (fn [x]
I think my misconception was not the missing identiy fun but rather that the
first element in the list is the function
that is evaluated.
so #(%) is trying to evaluate whatever % evaluates to, e.g. (1) and therefore
there is the
java.lang.ClassCastException: java.lang.Integer cannot be cast to
Hello, what you want here is identity :
(map identity (list 1 2 3))
Regards,
--
Laurent
2009/4/18 Michael Hunger
>
> I tried to use an anonymous function in map but it didn't work.
>
> user=> (map #(%) '(1 2 3))
> java.lang.ClassCastException: java.lang.Integer cannot be cast to
> clojure.la
I tried to use an anonymous function in map but it didn't work.
user=> (map #(%) '(1 2 3))
java.lang.ClassCastException: java.lang.Integer cannot be cast to
clojure.lang.IFn
but with a normal anonymous function it works as expected:
user=> (map (fn [x] x) '(1 2 3))
(1 2 3)
Thanks
Michael
P.S