120 lines
6.9 KiB
HTML
120 lines
6.9 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-SETQ 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/iss361_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss362.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss363_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/iss361_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss362.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss363_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue WITH-OPEN-FILE-SETQ Writeup</H2>
|
|
|
|
<PRE><B>Issue:</B> <A HREF="iss362.htm">WITH-OPEN-FILE-SETQ</A><P>
|
|
<B>References:</B> <A REL=DEFINITION HREF="../Body/m_w_open.htm#with-open-file"><B>WITH-OPEN-FILE</B></A><P>
|
|
<A REL=DEFINITION HREF="../Body/m_w_op_1.htm#with-open-stream"><B>WITH-OPEN-STREAM</B></A><P>
|
|
<A REL=DEFINITION HREF="../Body/m_w_in_f.htm#with-input-from-string"><B>WITH-INPUT-FROM-STRING</B></A><P>
|
|
<A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A><P>
|
|
Related issues: <A HREF="iss363.htm">WITH-OPEN-FILE-STREAM-EXTENT</A><P>
|
|
<B>Category:</B> CLARIFICATION<P>
|
|
<B>Edit history:</B> v1, 13 Feb 1991, Sandra Loosemore<P>
|
|
v2, 11 Mar 1991, Sandra Loosemore<P>
|
|
<P>
|
|
<B>Problem description:<P>
|
|
</B><P>
|
|
It isn't clear whether it is permissible for the variable bound to<P>
|
|
a stream by <A REL=DEFINITION HREF="../Body/m_w_open.htm#with-open-file"><B>WITH-OPEN-FILE</B></A>, <A REL=DEFINITION HREF="../Body/m_w_op_1.htm#with-open-stream"><B>WITH-OPEN-STREAM</B></A>, <A REL=DEFINITION HREF="../Body/m_w_in_f.htm#with-input-from-string"><B>WITH-INPUT-FROM-STRING</B></A>,<P>
|
|
or <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> may be explicitly assigned to within the body.<P>
|
|
The expansion of these macros must include some code to close the stream<P>
|
|
after executing the body forms. Can this code refer to the stream<P>
|
|
using the user-supplied variable, or must it use another "hidden"<P>
|
|
variable in case the user-supplied variable has been assigned to in<P>
|
|
the body forms?<P>
|
|
<P>
|
|
<B>Proposal (WITH-OPEN-FILE-SETQ:EXPLICITLY-VAGUE):<P>
|
|
</B><P>
|
|
Clarify that the consequences of altering the values of the variables <P>
|
|
bound to streams by <A REL=DEFINITION HREF="../Body/m_w_op_1.htm#with-open-stream"><B>WITH-OPEN-STREAM</B></A>, WITH-INPUT-FROM-STREAM,<P>
|
|
WITH-OUTPUT-TO-STREAM, and <A REL=DEFINITION HREF="../Body/m_w_open.htm#with-open-file"><B>WITH-OPEN-FILE</B></A> (by using <A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>SETQ</B></A>, for example)<P>
|
|
are undefined. A Common Lisp compiler may choose to issue a warning<P>
|
|
if such a variable appears in a <A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>SETQ</B></A>.<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B><P>
|
|
This is consistent with what CLtL says about altering the value of<P>
|
|
the counter variable in a <A REL=DEFINITION HREF="../Body/m_dotime.htm#dotimes"><B>DOTIMES</B></A> form.<P>
|
|
<P>
|
|
<B>Current Practice:<P>
|
|
</B><P>
|
|
Lucid CL, Allegro CL, the Chestnut Lisp-to-C translator, and Symbolics<P>
|
|
Common Lisp all implement <A REL=DEFINITION HREF="../Body/m_w_open.htm#with-open-file"><B>WITH-OPEN-FILE</B></A> in such a way that the <P>
|
|
user-supplied variable is referenced to close the stream.<P>
|
|
<P>
|
|
<B>Cost to Implementors:<P>
|
|
</B><P>
|
|
None, since this permits implementations to continue to use the<P>
|
|
"obvious" expansion.<P>
|
|
<P>
|
|
<B>Cost to Users:<P>
|
|
</B><P>
|
|
Probably none. Any user programs that depend on it working the other<P>
|
|
way are already clearly not portable.<P>
|
|
<P>
|
|
<B>Cost of non-adoption:<P>
|
|
</B><P>
|
|
The language specification will be vague. Users may have portability<P>
|
|
problems.<P>
|
|
<P>
|
|
<B>Performance impact:<P>
|
|
</B><P>
|
|
Negligible.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
Users will know what to expect and will avoid a portability pitfall.<P>
|
|
<P>
|
|
<B>Esthetics:<P>
|
|
</B><P>
|
|
Doesn't look too bad.<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
Kent Pitman notes:<P>
|
|
<P>
|
|
It probably is worth mentioning that the most common abuse of this<P>
|
|
situation I've seen is that sometimes users will create broadcast<P>
|
|
streams, echo streams, etc., or even implementation-dependent<P>
|
|
encapsulations of the indicated stream to the opened file and then set<P>
|
|
it back to the indicated variable. (Whether the later call to <A REL=DEFINITION HREF="../Body/f_close.htm#close"><B>CLOSE</B></A><P>
|
|
is a good idea to do to the compound stream which results is something<P>
|
|
that probably varies from implementation to implementation. This<P>
|
|
proposal certainly makes it more clear that users who do this are<P>
|
|
living on the edge.)<P>
|
|
<P>
|
|
Anyway, I just wanted to emphasize that the only scenario was not<P>
|
|
something bizarre like someone doing<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_w_open.htm#with-open-file"><B>WITH-OPEN-FILE</B></A> (TEMP ...)<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#print"><B>PRINT</B></A> X <A REL=DEFINITION HREF="../Body/t_stream.htm#stream"><B>STREAM</B></A>)<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>SETQ</B></A> X (+ 7 2)) ...)<P>
|
|
<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>
|