125 lines
8.1 KiB
HTML
125 lines
8.1 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Issue WITH-OPEN-FILE-DOES-NOT-EXIST Writeup</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="../Issues/iss360_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss361.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss362_w.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="../Issues/iss360_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss361.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss362_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue WITH-OPEN-FILE-DOES-NOT-EXIST Writeup</H2>
|
|
|
|
<PRE><B>Status:</B> Proposal STREAM-IS-NIL passed, Jun 89 X3J13<P>
|
|
<P>
|
|
<B>Issue:</B> <A HREF="iss361.htm">WITH-OPEN-FILE-DOES-NOT-EXIST</A><P>
|
|
<B>References:</B> CLtL page 422<P>
|
|
<B>Category:</B> Clarify<P>
|
|
<B>Edit history:</B> 17-Mar-89, Version 1<P>
|
|
<P>
|
|
<B>Problem description:<P>
|
|
</B>The documentation for <A REL=DEFINITION HREF="../Body/m_w_open.htm#with-open-file"><B>WITH-OPEN-FILE</B></A> (p 422) says:<P>
|
|
"WITH-OPEN-FILE evaluates the Forms of the body (an implict <A REL=DEFINITION HREF="../Body/s_progn.htm#progn"><B>PROGN</B></A>)<P>
|
|
with the variable Stream bound to a stream that reads or writes the<P>
|
|
file named by the value of Filename. The options are evaluated and<P>
|
|
used as keyword arguments to the function <A REL=DEFINITION HREF="../Body/f_open.htm#open"><B>OPEN</B></A>."<P>
|
|
<P>
|
|
It is not clear what to do when there is no stream<P>
|
|
"that reads or writes the file" named by Filename.<P>
|
|
Is the body evaluated? What is Stream bound to?<P>
|
|
<P>
|
|
Proposal: WITH-OPEN-FILE-DOES-NOT-EXIST:DONT-EVALUATE<P>
|
|
If the result of <A REL=DEFINITION HREF="../Body/f_open.htm#open"><B>OPEN</B></A> does not return a stream (eg returns <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>)<P>
|
|
Then the body of <A REL=DEFINITION HREF="../Body/m_w_open.htm#with-open-file"><B>WITH-OPEN-FILE</B></A> is not evaluated, <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> is returned.<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B> The contract that "the body is evaluated with ... bound to a stream"<P>
|
|
is maintained in the sense of a vacuous evalation.<P>
|
|
The alternatives are:<P>
|
|
To let the stream variable be bound to <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> (unintuitive and dangerous).<P>
|
|
If users want to Signal-An-Error in this case, they can use<P>
|
|
:if-does-not-exist :error <P>
|
|
The test for (<A REL=DEFINITION HREF="../Body/f_stmp.htm#streamp"><B>STREAMP</B></A> Stream) is probably done anyway,<P>
|
|
since the <A REL=DEFINITION HREF="../Body/s_unwind.htm#unwind-protect"><B>UNWIND-PROTECT</B></A> cleanup form can't call <A REL=DEFINITION HREF="../Body/f_close.htm#close"><B>CLOSE</B></A> on <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>.<P>
|
|
<P>
|
|
Proposal: <A HREF="iss361.htm">WITH-OPEN-FILE-DOES-NOT-EXIST:STREAM-IS-NIL</A><P>
|
|
Clarify the documentation to explain that:<P>
|
|
Stream is bound to the value returned by <A REL=DEFINITION HREF="../Body/f_open.htm#open"><B>OPEN</B></A>.<P>
|
|
Users of :if-does-not-exist <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> should check for a valid stream.<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B> This simple to implement, no extra testing is done.<P>
|
|
Users who use :if-does-not-exist <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> can wrap their body forms<P>
|
|
with (when (<A REL=DEFINITION HREF="../Body/f_stmp.htm#streamp"><B>STREAMP</B></A> Stream) ...)<P>
|
|
<P>
|
|
<B>Examples:<P>
|
|
</B>1. (<A REL=DEFINITION HREF="../Body/m_w_open.htm#with-open-file"><B>WITH-OPEN-FILE</B></A> (foo "no-such-file" :IF-DOES-NOT-EXIST nil)<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_rd_rd.htm#read"><B>READ</B></A> foo) t)<P>
|
|
DONT-EVALUATE: => <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, no I/O is done, do not read from *standard-input*<P>
|
|
STREAM-IS-NIL: => T, reads from *standard-input*<P>
|
|
<P>
|
|
2. (<A REL=DEFINITION HREF="../Body/m_w_open.htm#with-open-file"><B>WITH-OPEN-FILE</B></A> (foo "/no-dir" :direction :output :IF-DOES-NOT-EXIST nil)<P>
|
|
(format foo t) t)<P>
|
|
DONT-EVALUATE: => <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, no string is created.<P>
|
|
STREAM-IS-NIL: => T, creates a string and writes to it.<P>
|
|
<P>
|
|
<B>Current practice:<P>
|
|
</B> Symbolics and Lucid apparently implement STREAM-IS-NIL.<P>
|
|
<P>
|
|
<B>Cost to Implementors:<P>
|
|
</B> STREAM-IS-NIL: no cost.<P>
|
|
DONT-EVALUATE:<P>
|
|
Trivial? to test for :if-does-not-exist <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> and supply a <P>
|
|
test for (<A REL=DEFINITION HREF="../Body/f_stmp.htm#streamp"><B>STREAMP</B></A> Stream) in that case [or in every case].<P>
|
|
<P>
|
|
<B>Cost to Users:<P>
|
|
</B> DONT-EVALUATE: System tests for (<A REL=DEFINITION HREF="../Body/f_stmp.htm#streamp"><B>STREAMP</B></A> Stream), possibly extraneously.<P>
|
|
STREAM-IS-NIL: User must write a test for (<A REL=DEFINITION HREF="../Body/f_stmp.htm#streamp"><B>STREAMP</B></A> Stream).<P>
|
|
Probably no portable code uses :if-does-not-exist <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> without<P>
|
|
testing explicitly for (<A REL=DEFINITION HREF="../Body/f_stmp.htm#streamp"><B>STREAMP</B></A> Stream).<P>
|
|
<P>
|
|
<B>Cost of non-adoption:<P>
|
|
</B> The current situation is non-intuitive and/or confusing.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B> Users would know if the <A REL=DEFINITION HREF="../Body/f_stmp.htm#streamp"><B>STREAMP</B></A> test has been done or whether <P>
|
|
they must supply it.<P>
|
|
<P>
|
|
<B>Esthetics:<P>
|
|
</B><P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
<P>
|
|
<P>
|
|
GV-Info: CL-Cleanup-mailer@SAIL.Stanford.EDU at 21-Mar-89 16:03:29 from AG<P>
|
|
Return-Path: <CL-Cleanup-mailer@SAIL.Stanford.EDU><P>
|
|
Redistributed: xerox-cl-cleanup^.pa<P>
|
|
Received: from SAIL.Stanford.EDU ([36.86.0.194]) by Xerox.COM ; 21 MAR 89 16:03:30 PST<P>
|
|
Received: from STONY-BROOK.SCRC.Symbolics.COM (SCRC-STONY-BROOK.ARPA) by SAIL.Stanford.EDU with TCP; 21 Mar 89 16:01:17 PST<P>
|
|
Received: from EUPHRATES.SCRC.Symbolics.COM by STONY-BROOK.SCRC.Symbolics.COM via CHAOS with CHAOS-MAIL id 562394; Tue 21-Mar-89 18:59:52 EST<P>
|
|
Date: Tue, 21 Mar 89 18:59 EST<P>
|
|
From: David A. Moon <Moon@STONY-BROOK.SCRC.Symbolics.COM><P>
|
|
Message-ID: <19890321235935.6.MOON@EUPHRATES.SCRC.Symbolics.COM><P>
|
|
<P>
|
|
I think <A HREF="iss361.htm">WITH-OPEN-FILE-DOES-NOT-EXIST:STREAM-IS-NIL</A> is clearly correct,<P>
|
|
although I agree that CLtL doesn't really say.<P>
|
|
<P>
|
|
</PRE>
|
|
<HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|