I typed this into Clojure REPL (using the enclojure Netbeans plugin):
user=> "hello, world"
"hello, world"
nil
What’s the nil about?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Every function or macro call returns a value in Clojure, even things like
ifstatements or looping constructs or toplevel function definitions or print statements, which in other languages are “statements”. There’s no statement/expression dichotomy in Lisps; everything is an expression.So
printlnand friends print to standard-output as a side-effect and returnnil, as do most functions which don’t have anything useful to return.But typing a literal string at the REPL should return the string itself, as in digitalross’ post.
In the first case, the
hello worldline is what was printed to standard-output byprintln.nilis the returned value ofprintln. In the second case,"hello world"is the returned value of"hello world"since a string evaluates to itself. Nothing is printed to standard-output in this case.(SLIME and some other REPL interfaces will helpfully color standard-output (the
hello worldline above) differently from the returned value of what you typed at the REPL (nilabove), since it might be confusing otherwise.)This is what you should see at a REPL. What you posted must be an artifact of Enclojure.