The for
loop is returning a lazy sequence that is evaluated only as needed.
When you run the program inside the repl
the for result is realized in order to display the result on screen.
But when you run using lein run
result is never used so the collection is not realized.
You have a couple alternatives:
1) use doall
outside the for
loop for force lazy sequence realization
Ex:
(defn for-print
"Print the same thing 3 times"
[ p-string ]
(println (str "Checkpoint: " p-string))
(doall (for
[x [1 2 3]]
(printf "FOR: %s\n" p-string))))
2) since you're only printing which is a side effect and not really creating a collection you can use doseq.
Ex:
(defn for-print
"Print the same thing 3 times"
[ p-string ]
(println (str "Checkpoint: " p-string))
(doseq [x [1 2 3]]
(printf "FOR: %s\n" p-string)))