Clojure String Returns
just a quick question 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 is a String not displayed using the print function? Does the reader seem to be trying to resolve the return value of foo (which seems to be String) as a function? How should you determine foo that print will write a line on the command line?
I'm still a little weak at Clojure compared to other other Lisp fame, but that's not it, is it? Must be
(defn foo [] "bar") otherwise, you defined a function that tries to call the string "bar" as a function that is consistent with your error.
mress:10004 Z$ clj Clojure 1.2.0 user=> (defn foo [] "bar") #'user/foo user=> (foo) "bar" because Clojure tries to "resolve" the first element of any list as a function name when you are in the last status called a print function, it is called with one argument list (foo) whish is interpreted as a function call foo. so far so good.
but the foo function returns a list ("bar") that does not fit ... this is interpreted as a call to the "bar" function, which is not allowed.
if foo is similar (defn foo [] "bar") than it will work, because the print will not be received ("bar"), but just "bar" and print