When I run (println (iterate inc 0)) in my repl, I will get something like this:
user=> (println (iterate inc 0))
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 ....................
My expectation when I run the code is that repl shows nothing and just stuck because (iterate inc 0) never ends. But, I see (0 1 2 3 ....
(iterate inc 0) generates infinite sequence which never returns. If it never ends, then why println starts printing values?
In other words, why (println xx) is started being evaluated even if the input is never finished being evaluated?
printlndoes not need the whole sequence to be realized before printing, it does it on on-demand manner. "which never returns".(first (iterate inc 0))would return you0for the very same reason. - zerkms