just a quick question while looking at Clojure....
Given the following REPL Session:
Clojure 1.2.0
user=> "bar"
"bar"
user=> (print "bar")
barnil
user=> (defn foo [] ("bar"))
#'user/foo
user=> (foo)
java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0)
user=> (print foo)
#<user$foo user$foo@65dcc2a3>nil
user=> (print (foo))
java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn(NO_SOURCE_FILE:0)
Why isn't the String "bar" shown by the print function? It seems like the reader tries to resolve the return value of foo (which seems to be a String) as a function? How should be foo defined that print will write the string to the commandline?
I'm still a bit weak on Clojure as compared to various other Lisp-likes, but that's not right, is it? Should be
(defn foo [] "bar")
otherwise you've defined a function that tries to call the string "bar"
as a function, which is consistent with your error.
mress:10004 Z$ clj
Clojure 1.2.0
user=> (defn foo [] "bar")
#'user/foo
user=> (foo)
"bar"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With