[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
New issue: WITH-OPEN-FILE-DOES-NOT-EXIST
- To: email@example.com
- Subject: New issue: WITH-OPEN-FILE-DOES-NOT-EXIST
- From: peck@Sun.COM
- Date: Fri, 17 Mar 89 21:25:42 PST
Really a request for an editorial change, so users will know what
to expect. A user actually reported this as a bug...
Unless someone believes that STREAM-IS-NIL is wrong, this could just
be forwarded to editorial.
References: CLtL page 422
Edit history: 17-Mar-89, Version 1
The documentation for WITH-OPEN-FILE (p 422) says:
"WITH-OPEN-FILE evaluates the Forms of the body (an implict PROGN)
with the variable Stream bound to a stream that reads or writes the
file named by the value of Filename. The options are evaluated and
used as keyword arguments to the function OPEN."
It is not clear what to do when there is no stream
"that reads or writes the file" named by Filename.
Is the body evaluated? What is Stream bound to?
If the result of OPEN does not return a stream (eg returns NIL)
Then the body of WITH-OPEN-FILE is not evaluated, NIL is returned.
The contract that "the body is evaluated with ... bound to a stream"
is maintained in the sense of a vacuous evalation.
The alternatives are:
To let the stream variable be bound to NIL (unintuitive and dangerous).
If users want to Signal-An-Error in this case, they can use
The test for (STREAMP Stream) is probably done anyway,
since the UNWIND-PROTECT cleanup form can't call CLOSE on NIL.
Clarify the documentation to explain that:
Stream is bound to the value returned by OPEN.
Users of :if-does-not-exist NIL should check for a valid stream.
This simple to implement, no extra testing is done.
Users who use :if-does-not-exist NIL can wrap their body forms
with (when (STREAMP Stream) ...)
1. (WITH-OPEN-FILE (foo "no-such-file" :IF-DOES-NOT-EXIST nil)
(READ foo) t)
DONT-EVALUATE: => NIL, no I/O is done, do not read from *standard-input*
STREAM-IS-NIL: => T, reads from *standard-input*
2. (WITH-OPEN-FILE (foo "/no-dir" :direction :output :IF-DOES-NOT-EXIST nil)
(format foo t) t)
DONT-EVALUATE: => NIL, no string is created.
STREAM-IS-NIL: => T, creates a string and writes to it.
Symbolics and Lucid apparently implement STREAM-IS-NIL.
Cost to Implementors:
STREAM-IS-NIL: no cost.
Trivial? to test for :if-does-not-exist NIL and supply a
test for (STREAMP Stream) in that case [or in every case].
Cost to Users:
DONT-EVALUATE: System tests for (STREAMP Stream), possibly extraneously.
STREAM-IS-NIL: User must write a test for (STREAMP Stream).
Probably no portable code uses :if-does-not-exist NIL without
testing explicitly for (STREAMP Stream).
Cost of non-adoption:
The current situation is non-intuitive and/or confusing.
Users would know if the STREAMP test has been done or whether
they must supply it.