(defn square [x]
(do
(println (str "Processing: " x))
(* x x)))
(println (map square '(1 2 3 4 5)))
Why is the output
(Processing: 1
Processing: 2
1 Processing: 3
4 Processing: 4
9 Processing: 5
16 25)
not
(Processing: 1
1 Processing: 2
4 Processing: 3
9 Processing: 4
16 Processing: 5
25)
?
printlnuses[[x & xs] xs]destructuring form in its implementation. This is equivelent to[x (first xs), xs (next xs)]andnextis less lazy thanrest, so it realizes the two items before printing the first.For example,