I am new to Clojure and have found that when I loop over this vector in clojure using a list comprehension I get some nils at the end.
(def myVec [1,2,3])
user=> (for [x myVec] (println x))
(1
2
3
nil nil nil)
I get the same thing using map
user=> (map println myVec)
(1
2
3
nil nil nil)
What causes the nill to be printed in these cases?
Those
nilare the return value ofprintln. Every time you callthe
printlnfunction printssomethingon the standard output, and then returnsnil. The overall effect in your code is that you see all the side effects (I/O) of allprintlninvocations, then the REPL prints the return value coming from each and every invocation (e.g. three timesnil).