Consider the following code in clojure:
(let [a (find-a), b (find-b)] (println a) (println b) )
Where b is a sequence. There are also some println statements in function find-a. What I would expect to see in standard outputs is: a, results from println statements in find-a, b. However, what I do get is : a, part of b, results from println statements in find-a, rest of b.
Is this due to lazy evaluation of sequences?
Nothing in this code is inherently lazy - it should all get executed in the correct sequence.
However, depending on what a and b are there could be something lazy embedded inside them, which only gets executed when (println a) and (println b) are executed. In particular, if a and b are lazy sequences created with map or something similar then the later parts of the sequences will only get evaluated when execution is forced within the println statement. To be more specific than that, you'd need to describe the internal structure of a and b.
I actually suspect however that the problem could be due to buffers not getting flushed - see Clojure - Side Effects Happening Out Of Order
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With