Unable to cast object of type 'System.String' to type 'clojure.lang.IFn'

61 views
Skip to first unread message

cljneo

unread,
Dec 31, 2010, 6:32:48 AM12/31/10
to vsclojure
First thanks for the vsClojure extension. I have been waiting for this
for a long time.

I am new to clojure and obviously to vsClojure. I tried the pig-latin
example in the Clojure Article (http://java.ociweb.com/mark/clojure/
article.html) where I put it in a new project like this:

(ns program)

(def vowel? (set "aeiou"))

(defn pig-laten [word]
(let [first-letter (first word)]
(if (vowel? first-letter)
(str word "ay")
(str (subs word 1) first-letter "ay"))))

(defn main [& args] (
(pig-laten "red")
(pig-laten "orange")))

(main)


but I get this error when I compile:

System.InvalidCastException was unhandled
Message=Unable to cast object of type 'System.String' to type
'clojure.lang.IFn'.
Source=Anonymously Hosted DynamicMethods Assembly
StackTrace:
at main(Closure , Object )
at clojure.lang.RestFnImpl.doInvoke(Object args)
at clojure.lang.RestFn.invoke()
at clojure.lang.RestFnImpl.invoke()
at lambda_method(Closure )
at AFunction_impl.invoke()
at REPLCall(Closure )
at clojure.lang.Compiler.eval(Object form)
at clojure.lang.Compiler.load(TextReader rdr, String
sourcePath, String sourceName, String relativePath)
at clojure.lang.Compiler.loadFile(String filename)
at clojure/main
$fn__16728$load_script__16730.__invokeHelper_1(clojure/main
$fn__16728$load_script__16730_base this, Object path) in main.clj:line
220
at clojure/main$fn__16728$load_script__16730.invoke(Object )
at clojure/main
$fn__16735$init_opt__16737.__invokeHelper_1(clojure/main
$fn__16735$init_opt__16737_base this, Object path) in main.clj:line
225
at clojure/main$fn__16735$init_opt__16737.invoke(Object )
at clojure/main
$fn__16756$initialize__16758.__invokeHelper_2(clojure/main
$fn__16756$initialize__16758_base this, Object args, Object inits) in
main.clj:line 253
at clojure/main$fn__16756$initialize__16758.invoke(Object ,
Object )
at clojure/main
$fn__16796$null_opt__16798.__invokeHelper_2(clojure/main
$fn__16796$null_opt__16798_base this, Object args, Object inits) in
main.clj:line 278
at clojure/main$fn__16796$null_opt__16798.invoke(Object ,
Object )
at clojure/main$fn__16835$main__16837.__invokeHelper_0v(clojure/
main$fn__16835$main__16837_base this, Object args) in main.clj:line
353
at clojure/main$fn__16835$main__16837.doInvoke(Object )
at clojure.lang.RestFn.invoke(Object arg1, Object arg2)
at clojure.lang.Var.invoke(Object arg1, Object arg2)
at clojure.lang.AFn.ApplyToHelper(IFn ifn, ISeq arglist)
at clojure.lang.Var.applyTo(ISeq arglist)
at Clojure.CljMain.Main(String[] args)
InnerException:


Is this an error in the clojureclr or in vsClojure. Any help is
appreciated.

jmis

unread,
Dec 31, 2010, 8:40:08 PM12/31/10
to vsclojure
Your main function is attempting to execute the string returned from
the pig-laten function call which is not possible. Instead, you want
to aggregate and return the results of the two pig-laten calls.
Here's two examples of how to do that:

(defn main [& args]
(list (pig-laten "red") (pig-laten "orange")))

(defn main [& args]
(map pig-laten '("red" "orange")))

cljneo

unread,
Jan 1, 2011, 6:59:10 AM1/1/11
to vsclojure
Thanks for pointing the error. I changed the program to this:

(ns program)

(def vowel? (set "aeiou"))

(defn pig-laten [word]
(let [first-letter (first word)]
(if (vowel? first-letter)
(str word "ay")
(str (subs word 1) first-letter "ay"))))

(defn main [& args] (
(print (list (pig-laten "red") (pig-laten "orange")))))

(main)

but I get this error upon building:

System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.

jmis

unread,
Jan 7, 2011, 8:40:59 PM1/7/11
to vsclojure
Sorry about the slow reply. You're attempting to execute the nil
return by the print function. The follow main function should work
for you.

(defn main [& args]
Reply all
Reply to author
Forward
0 new messages