I’m trying out the examples from the SCI readme, and I’m stuck in this one. What am I doing wrong here? (StringWriter is imported)
This is because of laziness
Try moving the sci/binding around the printing of the result
Friggin laziness
So,
(let [sw (StringWriter.)]
(sci/binding [sci/out sw]
(let [result (sci/eval-string "(map print (range 10))")]
(println "Output:" (str sw))
(println "Result:" result))))
Doesn’t throw, but also produces the result:
Output:
Result: (nil nil nil nil nil nil nil nil nil nil)
Which doesn’t align with the readme.what do you see in the readme?
you're still experiencing laziness here since the printing of the result realizes the lazy sequence, the stringwriter is still empty
It says "IF the lazy sequences was realized"
but it's not
Right, switching the order and introducing a doall now makes it kind of like the output given in the readme:
Result: (nil nil nil nil nil nil nil nil nil nil)
Output: 0123456789
it's just the same problem with binding and dynamic vars in clojure
I can’t say that I love default laziness.
Yeah, but usually that’s obscured by the REPL forcing realize on everything for you. This one you had cleverly manipulated to be hair-tearing.
yep, it's confusing
Thanks