Problem 4 : java.lang.Long cannot be cast to clojure.lang.IFn

1,850 views
Skip to first unread message

Roelof Wobben

unread,
Apr 16, 2014, 12:48:07 PM4/16/14
to 4clo...@googlegroups.com
Problem 4 looks like this :

(= __ (conj '(2 3 4) 1))

So in my opinion the answer must be (1 2 3 4)

But then I see this error :  java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IFn

Can anyone give me a hint what I do wrong ?

Roelof

Robert Marianski

unread,
Apr 16, 2014, 1:05:19 PM4/16/14
to 4clo...@googlegroups.com
(1 2 3 4) tries to call 1 as a function.

Try quoting it: '(1 2 3 4)

Or: (list 1 2 3 4)

Robert
> --
> You received this message because you are subscribed to the Google Groups "4Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to 4clojure+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Seven Hong

unread,
Apr 26, 2014, 8:14:54 PM4/26/14
to 4clo...@googlegroups.com
If you write (1 2 3 4) there, then Clojure REPL will think 1 is a function as 1 is placed at first place of the list. In Clojure, integer number is Long type by default, and since REPL is considering 1 as a function, it's trying to convert 1's type(which is Long) into function type(which is IFn) by casting it. That's why you have this error message.

You were right, conj-ing a 1 into list of 2 3 4, is a list of 1 2 3 4. You just need a quote in front of the list in order to stop REPL evaluating the list as a function call. That's why it's '(1 2 3 4).
Reply all
Reply to author
Forward
0 new messages