[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

with-open-stream and with-open-file

CLtL says that the stream (file) scoped by with-open-stream
(with-open-file) is closed when the form is exited, independent of
exit-reason.  I would like people to consider the following allowance:
that if the stream variable is NIL during the close operation, then the
stream (file) is not closed.  Thus
	(with-open-stream (stream constructor)
	  (prog1 stream (setq stream nil)))
would evaluate to an open stream.  The strict reading of CLtL says that
the stream should be closed and the stream, not the variable, should
be considered to have dynamic extent.  (I'd quote, except my book is
packed.)  I don't like the word "considered" as it could be interpreted
to legitimize not closing the stream.

Personally, I have found the above technique (setting the stream
variable to nil and returning the stream) as quite useful; the Symbolics
implementation already implementing the relaxation.  I ask that the
language be clarified.

Also, the (prog1 stream (setq stream nil)) is a cliche which can also be
written as (shiftf stream nil).  For many months I have not liked either
of those forms; the way they look, not what they do.  Unfortunately, the
best form I've been able to think of is (grab-and-clear stream) and I
don't like that very much either.