I'm a Clojure newbie. I'm trying to understand why the second form doesn't work:
First form:
user=>(def nums(range 3))
(0 1 2)
user=>(map #(list %1) nums)
((0) (1) (2))
Second form:
user=> (map #(list %1) (0 1 2))
java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
(NO_SOURCE_FILE:0)
The problem is the expression (0 1 2)
, which is interpreted as 0
applied to 1
and 2
; that's impossible because 0
isn't a function.
(map #(list %1) '(0 1 2))
works as intended, though.
Because (0 1 2)
means call function 0 with args 1 and 2, but 0 is not a function. So you need to make is a list rather than function application using quote or list function i.e '(0 1 2)
OR (list 0 1 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With