mogenslund/liquid

(doall (map inc [1 2 3])) evals to lazy seq

maacl opened this issue · 4 comments

maacl commented

doall should force the sequence.

I think it does. It is just still a lazy sequence. If you compare with the repl, I think the repl applies a pr-str to the result, which prints the evaluated sequence. Try the following in a repl:

(type (doall (map inc [1 2 3])))

it will evaluate to clojure.lang.LazySeq.

In Liquid try:

(doall (map #(println %) [1 2 3])) 

Notice the sideeffect is executed!

Last. In Liquid do

(pr-str (doall (map inc [1 2 3])))

Now you get the correct output.

I can change my code to apply pr-str automatically, but I think I prefer it as an explicit option to avoid printing endless sequences.

maacl commented

clojure.lang.LazySeq is its type, it is not a meaningful representation. It think you should consider emulating CIDER's behaviour when it comes to long/infinite sequences.

I think you have a point.

I will try out how CIDER handles my edge cases and adjust my local implementation accordingly and use it for some days to check if there are any unexpected side effects.

I have made a commit now. It uses pr-str when the output is not a string. Also pr-str truncates long lists using the global *print-length* variable. (I did not know that one, but found it by inspecting CIDERs source code.)

I also think it works better now. Thank you @maacl