sci

henrik 2025-07-23T07:30:58.139669Z

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)

✅ 1
borkdude 2025-07-23T07:45:48.078779Z

This is because of laziness

borkdude 2025-07-23T07:46:31.186499Z

Try moving the sci/binding around the printing of the result

👍 1
henrik 2025-07-23T07:48:07.132379Z

Friggin laziness

henrik 2025-07-23T07:48:45.489719Z

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.

borkdude 2025-07-23T07:49:18.890439Z

what do you see in the readme?

henrik 2025-07-23T07:49:36.547879Z

borkdude 2025-07-23T07:49:53.111499Z

you're still experiencing laziness here since the printing of the result realizes the lazy sequence, the stringwriter is still empty

borkdude 2025-07-23T07:50:47.544869Z

It says "IF the lazy sequences was realized"

borkdude 2025-07-23T07:50:49.166209Z

but it's not

henrik 2025-07-23T07:52:05.534759Z

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 

borkdude 2025-07-23T07:52:47.481969Z

it's just the same problem with binding and dynamic vars in clojure

henrik 2025-07-23T07:52:49.933869Z

I can’t say that I love default laziness.

henrik 2025-07-23T07:53:25.880319Z

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.

borkdude 2025-07-23T07:53:44.398089Z

yep, it's confusing

henrik 2025-07-23T07:54:14.483929Z

Thanks