(rontolisp) docs
← Macros

with-open-stream

(with-open-stream (var stream-form) body...)

Binds var to the stream produced by stream-form, evaluates the body forms with that binding and closes the stream afterwards, returning the value of the last body form. It is with-open-file without the open: the stream is one you already have (a socket, a string stream, the result of a portable open call). On the interpreter and the JVM the body is wrapped in unwind-protect, so the stream closes on every exit; the WASM backends keep the close-after-body shape.

That is the shorthand; with-open-stream is the general form, shown statically because it needs a stream you opened yourself:

(with-open-stream (s (open "f.txt" :direction :input))
  (read-line s)) ; => "hello"