I need to close a stream created with an I / O string
This question says it all. I'm wondering because clhs ismake-string-input-stream
not for specifying and the example code is not showing closure. But the expansion with-input-from-string
ends the stream.
(with-input-from-string (stream "hallo")
)
becomes
(LET ((#:STRING1525 "hallo"))
(LET ((STREAM (MAKE-STRING-INPUT-STREAM #:STRING1525 0)))
(MULTIPLE-VALUE-PROG1 (UNWIND-PROTECT (PROGN) (CLOSE STREAM)))))
source to share
The garbage collector will take care of cleaning it up if you don't close it before reusing the variable. Since string input streams have no side effects, CLOSE
it does nothing.
It would be different for output streams, because closing the stream might be required for side effects such as flushing the last bit of the buffered output (although you could call FORCE-OUTPUT
orFINISH-OUTPUT
).
source to share