Scaramaccai wrote on Thursday, February 11, 2016 at 8:32 AM: >I'm learning Clojure, and I find difficult to understand where a specific >compiler error happens:
The stacktraces can be pretty daunting at first, unfortunately. How are you compiling / running the code? That will have some bearing on how errors are reported. The exception you are seeing is a runtime failure so part of the stacktrace will show the line that initiated the call — line 100 — but other parts of the stacktrace should provide the path to the actual exception. >java.lang.ClassCastException: java.lang.Long cannot be cast to >clojure.lang.IPersistentCollection, compiling:(fwpd/core.clj:100:1) I created a new Clojure app with this as the main namespace: (ns fib3.core (:gen-class)) (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)))) (defn -main "I don't do a whole lot ... yet." [& args] (println (fib-seq3 5))) When I run this (via Boot — see below for Leiningen), I get: clojure.lang.ExceptionInfo: java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IPersistentCollection ... clojure.core/conj/invokeStatic core.clj: 82 clojure.core/conj core.clj: 82 fib3.core/fib-seq3/invokeStatic core.clj: 10 fib3.core/fib-seq3 core.clj: 4 fib3.core/fib-seq3/invokeStatic core.clj: 6 fib3.core/fib-seq3 core.clj: 4 fib3.core/-main/invokeStatic core.clj: 15 fib3.core/-main core.clj: 12 Line 10 is (fib-seq3 (conj b coll) b (+ a b) (inc k) to) Reading bottom to top for lines reported in our code we see: -main is defined on line 12 -main makes a call on line 15 to… fib-seq3 which is defined on line 4… …which makes a call on line 6 to… fib-seq3 which is defined on line 4… …which makes a call on line 10 to… clojure.core/conj which is where the failure occurs. Since I have direct linking enabled with Boot, I wanted to check whether running the code via Leiningen was different (where I do not have direct linking enabled): Exception in thread "main" java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IPersistentCollection, compiling:(/private/var/folders/p1/30gnjddx6p193frh670pl8nh0000gn/T/form-init8259964769198669862.clj:1:125) … Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.IPersistentCollection at clojure.core$conj__4345.invokeStatic(core.clj:82) at clojure.core$conj__4345.invoke(core.clj:82) at fib3.core$fib_seq3.invokeStatic(core.clj:10) at fib3.core$fib_seq3.invoke(core.clj:4) at fib3.core$fib_seq3.invokeStatic(core.clj:6) at fib3.core$fib_seq3.invoke(core.clj:4) at fib3.core$_main.invokeStatic(core.clj:15) at fib3.core$_main.doInvoke(core.clj:12) I omitted the top-level stacktrace (because it relates to clojure.main which is in turn running the actual code above) but in the cause we see the same sequence of line numbers as with Boot above. Does that help? Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood -- 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 patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.