Reputation: 1136
I'm learning Clojure, and I find difficult to understand where a specific compiler error happens:
java.lang.ClassCastException: java.lang.Long cannot be cast to
clojure.lang.IPersistentCollection, compiling:(fwpd/core.clj:100:1)
Line 100 is just:
(fib-seq3 5)
So it says nothing, because in fact the error is in the fib-seq3 function (parameters to a "conj" call are inverted, see below).
Is this normal? No way to know where an error is???
Just for reference, here's the code (again, I know where the error is; I just don't understand how was I supposed to find it, given that the message doesn't tell me at which line it happens):
(defn fib-seq3
([to]
(fib-seq3 [] 0 1 0 to))
([coll a b k to]
(if (= k to)
coll
(fib-seq3 (conj b coll) b (+ a b) (inc k) to)))
(fib-seq3 5)
Upvotes: 3
Views: 154
Reputation: 1136
The problem is that I was using REPL (Vim+Fireplace) to execute the code. Executing using lein repl
fixed the problem.
@Leonid @amalloy:
(.printStackTrace *e)
gives the proper stacktrace in the REPL (even from inside Fireplace, using "cqp" which gives the REPL prompt), so thank you very much for the comment (didn't know that!)
Upvotes: 1
Reputation: 51450
Stack traces in Clojure suck. In fact, error messages were rated by Clojure community as the top priority area for improvements, as well as Clojure most frustrating part.
This problem is not new. There was no considerable improvements in Clojure stack traces for quite a long time. But Clojure team is fully aware of this situation, so we could hope for improvements.
To better understand Clojure stack traces try reading Clojure Stack Traces for the Uninitiated. Though the article is somewhat old, it's still relevant.
In short, you should look for so-called "cause trace", which is a second part of any Clojure stack trace and starts with "Caused by" phrase.
Upvotes: 3