PersistentVector and clojure.lang.Named

1,700 views
Skip to first unread message

Arnoldo Muller

unread,
May 18, 2011, 10:44:28 AM5/18/11
to Clojure
Hello,

I am trying to compile a project with lein. The program source files
can be interpreted successfully (using swank-clojure) but when I try
to do "lein compile" or "lein jar" I get:

Exception in thread "main" java.lang.ClassCastException:
clojure.lang.PersistentVector cannot be cast to clojure.lang.Named
(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:5440)
at clojure.lang.Compiler.eval(Compiler.java:5415)
at clojure.lang.Compiler.eval(Compiler.java:5391)
at clojure.core$eval.invoke(core.clj:2382)
at clojure.main$eval_opt.invoke(main.clj:235)
at clojure.main$initialize.invoke(main.clj:254)
at clojure.main$null_opt.invoke(main.clj:279)
at clojure.main$main.doInvoke(main.clj:354)
at clojure.lang.RestFn.invoke(RestFn.java:422)
at clojure.lang.Var.invoke(Var.java:369)
at clojure.lang.AFn.applyToHelper(AFn.java:165)
at clojure.lang.Var.applyTo(Var.java:482)
at clojure.main.main(main.java:37)
Caused by: java.lang.ClassCastException: clojure.lang.PersistentVector
cannot be cast to clojure.lang.Named
at clojure.core$name.invoke(core.clj:1245)
at clojure.core$root_resource.invoke(core.clj:4712)
at clojure.core$load_one.invoke(core.clj:4729)
at clojure.core$compile$fn__4516.invoke(core.clj:4916)
at clojure.core$compile.invoke(core.clj:4915)
at user$eval7.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:5424)
... 12 more
Compilation failed.

The source code looks like:

(ns graphcluster.colorize-map
(:gen-class)
(:use clojure.contrib.command-line)
(:require graphcluster.core)
(:require clojure.contrib.str-utils)
)
; function definitions, they all run in swank-clojure
(defn -main [& args]
(let [lines (line-seq (java.io.BufferedReader. *in*)
]
(print (colorize (clojure.contrib.str-utils/str-join "\n" lines)))
))

In graphcluster.core there are some defs. I have for instance a sketch
object from incanter.processing .

I am using leiningen 1.5.2 and Clojure 1.2. Do you have any ideas
about the nature of this error?

Thanks!

Arnoldo

Stuart Sierra

unread,
May 18, 2011, 12:13:30 PM5/18/11
to clo...@googlegroups.com
A compilation error like "Foo cannot be cast to Bar" usually means you have a syntax error -- a Foo where you should have a Bar.  In this case, you have a Vector where the compiler is expecting a Named thing, such as a Keyword or Symbol. 

Check the syntax of your source files and project.clj carefully.

Oh, and FYI, Clojure is never interpreted. SLIME just invokes the compiler on individual definitions.

-Stuart Sierra
clojure.com

Alan Malloy

unread,
May 18, 2011, 3:58:29 PM5/18/11
to Clojure
You are missing a close-paren in

(let [lines (line-seq (java.io.BufferedReader. *in*)]

The compiler would certainly complain about this from swank, so I get
the feeling you haven't pasted your actual code. Did you make some
edits?

Also, those free-standing ) and ] characters make me dizzy. My feeling
is that, when *some* parens are on new lines and some are bundled
together, it indicates that the programmer is still thinking in terms
of blocks and statements, rather than expressions: "let introduces a
new block so its close paren needs a new line, but colorize is just an
expression so I'll pile it up with the others". Of course you can
format your code however you want, but *everything* is an expression,
and it's usual to just pile up N close-braces when N expressions end.
Reply all
Reply to author
Forward
0 new messages