getting values outof a loop (Clojure) -


if make loop how possible values of variable in standard out each turn? not talking printing them on screen, because long in loop values going proceed loop , not coming out, 1 coming standard out closing value. example: (loop [x 0] (if (< x 5) (recur (inc x)) 1234567890))) 1234567890 loop ends, want 0, 1, 2, 3 , 4 std.out.

well, loop not loop recursion point. if want collect values can use kind of accumulator:

(loop [x 0 acc []]   (if (< x 5)     (recur (inc x) (conj acc x))     (conj acc 1234567890))) 

unless recursion want kind of map or for (list comprehension) better choice.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -