1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Issues/iss330_w.htm
2024-04-01 10:24:07 +02:00

141 lines
10 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 STRING-OUTPUT-STREAM-BASHING 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/iss329_w.htm">
<LINK REL=UP HREF="../Issues/iss330.htm">
<LINK REL=NEXT HREF="../Issues/iss331_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/iss329_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss330.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss331_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue STRING-OUTPUT-STREAM-BASHING Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss330.htm">STRING-OUTPUT-STREAM-BASHING</A><P>
<B>References:</B> <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A><P>
<A REL=DEFINITION HREF="../Body/f_get_ou.htm#get-output-stream-string"><B>GET-OUTPUT-STREAM-STRING</B></A><P>
<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A><P>
Related issues: <A HREF="iss240.htm">MAPPING-DESTRUCTIVE-INTERACTION</A><P>
<A HREF="iss364.htm">WITH-OUTPUT-TO-STRING-APPEND-STYLE</A><P>
<B>Category:</B> CLARIFICATION<P>
<B>Edit history:</B> V1, 12 Feb 1991, Sandra Loosemore<P>
<P>
<B>Problem description:<P>
</B><P>
Is it valid to call <A REL=DEFINITION HREF="../Body/f_get_ou.htm#get-output-stream-string"><B>GET-OUTPUT-STREAM-STRING</B></A> on a stream bound by<P>
WITH-OUTPUT-TO-STRING? If so, must the <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> still <P>
return a string containing *all* of the collected output to the <P>
stream? Or should only output collected since the last call to<P>
<A REL=DEFINITION HREF="../Body/f_get_ou.htm#get-output-stream-string"><B>GET-OUTPUT-STREAM-STRING</B></A> be returned?<P>
<P>
The ambiguity exists for both the case where no string argument is<P>
provided to <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> (where the string is returned as its<P>
value) and where a string with a fill pointer is provided and<P>
destructively modified. There is also a problem with string output<P>
streams created by calls to <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> when its stream argument is <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> or<P>
a string with a fill pointer, although users have to try harder to<P>
get their hands on the stream object in that case.<P>
<P>
It is also not clear what the effects of destructive modifications to<P>
a string supplied as an argument to <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> or <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A><P>
are supposed to be.<P>
<P>
<B>Proposal (STRING-OUTPUT-STREAM-BASHING:UNDEFINED):<P>
</B><P>
Clarify that the consequences of calling <A REL=DEFINITION HREF="../Body/f_get_ou.htm#get-output-stream-string"><B>GET-OUTPUT-STREAM-STRING</B></A><P>
on a stream created by <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> or <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> are undefined.<P>
In the cases where a string argument with a fill pointer is supplied<P>
as an argument to <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> or <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A>, the consequences<P>
are undefined if destructive modifications are performed directly on<P>
the string during the dynamic extent of the call.<P>
<P>
<B>Examples:<P>
</B><P>
#1: (<A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>with-output-to-string</B></A> (s)<P>
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>prin1</B></A> 'foo s) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#print"><B>print</B></A> (<A REL=DEFINITION HREF="../Body/f_get_ou.htm#get-output-stream-string"><B>get-output-stream-string</B></A> s))<P>
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>prin1</B></A> 'bar s) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#print"><B>print</B></A> (<A REL=DEFINITION HREF="../Body/f_get_ou.htm#get-output-stream-string"><B>get-output-stream-string</B></A> s)))<P>
<P>
=&gt; Under proposal UNDEFINED, this program is in error.<P>
<P>
#2: (let ((x (<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>make-array</B></A> 100 :element-type '<A REL=DEFINITION HREF="../Body/t_std_ch.htm#standard-char"><B>standard-char</B></A> :fill-pointer 0)))<P>
(<A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>with-output-to-string</B></A> (s x)<P>
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>prin1</B></A> 'foo s) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#print"><B>print</B></A> (<A REL=DEFINITION HREF="../Body/f_get_ou.htm#get-output-stream-string"><B>get-output-stream-string</B></A> s))<P>
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>prin1</B></A> 'bar s) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#print"><B>print</B></A> (<A REL=DEFINITION HREF="../Body/f_get_ou.htm#get-output-stream-string"><B>get-output-stream-string</B></A> s)))<P>
x)<P>
<P>
=&gt; Under proposal UNDEFINED, this program is in error.<P>
<P>
#3: (let ((x (<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>make-array</B></A> 100 :element-type '<A REL=DEFINITION HREF="../Body/t_std_ch.htm#standard-char"><B>standard-char</B></A> :fill-pointer 0)))<P>
(<A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>with-output-to-string</B></A> (s x)<P>
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>prin1</B></A> 'foo s) (<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (<A REL=DEFINITION HREF="../Body/f_fill_p.htm#fill-pointer"><B>fill-pointer</B></A> x) 0)<P>
(<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>prin1</B></A> 'bar s) (<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> (<A REL=DEFINITION HREF="../Body/f_fill_p.htm#fill-pointer"><B>fill-pointer</B></A> x) 0))<P>
x)<P>
<P>
=&gt; Under proposal UNDEFINED, this program is in error.<P>
<P>
<B>Rationale:<P>
</B><P>
Calling <A REL=DEFINITION HREF="../Body/f_get_ou.htm#get-output-stream-string"><B>GET-OUTPUT-STREAM-STRING</B></A> is a destructive modification of<P>
the stream being manipulated by <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> or <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A>. <P>
It would be consistent with issue <A HREF="iss240.htm">MAPPING-DESTRUCTIVE-INTERACTION</A> <P>
to prohibit this. Likewise, some implementations become confused if<P>
the string with fill pointer underlying a string output stream is<P>
modified directly.<P>
<P>
<B>Current Practice:<P>
</B><P>
Lucid, Allegro, and Symbolics Genera all print &quot;FOO&quot; and &quot;BAR&quot; and <P>
return &quot;&quot; from test case 1, but vary in the behavior of the other<P>
cases.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
No implementation would be forced to change by this proposal.<P>
<P>
<B>Cost to Users:<P>
</B><P>
Probably few user programs rely on any particular behavior here.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
Continuing vagueness in the language specification.<P>
<P>
<B>Performance impact:<P>
</B><P>
N/A<P>
<P>
<B>Benefits:<P>
</B><P>
The costs of non-adoption are avoided.<P>
<P>
<B>Esthetics:<P>
</B><P>
It might be more esthetic to try to specify the behavior. In the<P>
case of <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> where no string argument is provided<P>
and <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> with a stream argument of <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, the behavior could easily<P>
be explained in terms of the obvious implementation of these constructs <P>
using <A REL=DEFINITION HREF="../Body/f_mk_s_2.htm#make-string-output-stream"><B>MAKE-STRING-OUTPUT-STREAM</B></A> and <A REL=DEFINITION HREF="../Body/f_get_ou.htm#get-output-stream-string"><B>GET-OUTPUT-STREAM-STRING</B></A>. However,<P>
there are no corresponding primitives for creating a string stream from<P>
a string with a fill pointer.<P>
<P>
<B>Discussion:<P>
</B><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>