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

122 lines
7.5 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-OUTPUT-TO-STRING-APPEND-STYLE 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/iss363_w.htm">
<LINK REL=UP HREF="../Issues/iss364.htm">
<LINK REL=NEXT HREF="../Issues/iss365_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/iss363_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss364.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss365_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue WITH-OUTPUT-TO-STRING-APPEND-STYLE Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss364.htm">WITH-OUTPUT-TO-STRING-APPEND-STYLE</A><P>
<P>
<B>References:</B> CLtL, pages 331, 386<P>
<P>
<B>Category:</B> CLARIFICATION<P>
<P>
<B>Edit history:</B> Version 1, 25-Mar-88 JonL<P>
Version 2, 29-Mar-88 JonL (fix typos; comments by Daniels)<P>
Version 3, 23-May-88 JonL (fix nits raised by Masinter)<P>
Version 4, 23-May-88 JonL (change issue name -- only 1 proposal)<P>
Version 5, 7-Jun-88 Masinter (more nits)<P>
<P>
<B>Problem description:<P>
</B><P>
CLtL p386 says that FORMATting to a <A REL=DEFINITION HREF="../Body/f_fill_p.htm#fill-pointer"><B>fill-pointer</B></A>'d string should add<P>
characters &quot;as if by use of VECTOR-PUSH-EXTEND&quot;; but CLtL p331 says that<P>
<A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> will work &quot;as if using <A REL=DEFINITION HREF="../Body/f_vec_ps.htm#vector-push-extend"><B>VECTOR-PUSH-EXTEND</B></A> if the<P>
string is adjustable, and otherwise as if using VECTOR-PUSH&quot;. It's very<P>
unlikely that the original authors of these parts intended differing<P>
semantics for these two cases. Furthermore, the semantics for<P>
<A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> permit the inconspicuous loss of characters<P>
written to the string, since <A REL=DEFINITION HREF="../Body/f_vec_ps.htm#vector-push"><B>VECTOR-PUSH</B></A> will just &quot;drop on the floor&quot;<P>
any characters that would go beyond the end.<P>
<P>
<P>
<B>Proposal (WITH-OUTPUT-TO-STRING-APPEND-STYLE:VECTOR-PUSH-EXTEND):<P>
</B><P>
Change the documentation of <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> to be like that under <P>
<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A>. That is, replace the first sentence of the next-to-last paragraph <P>
on CLtL p331 by:<P>
&quot;If *string* is specified, it must be a string with a fill pointer; <P>
the output is incrementally appended to the string (as if by use of<P>
<A REL=DEFINITION HREF="../Body/f_vec_ps.htm#vector-push-extend"><B>VECTOR-PUSH-EXTEND</B></A>).&quot;<P>
<P>
<P>
<B>Test Case: <P>
</B> (<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>let</B></A> ((str (<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>make-array</B></A> 4 :element-type 'string-char :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 str) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#princ"><B>princ</B></A> &quot;You Luz, Bunkie!&quot; s))<P>
str)<P>
CLtL behaviour will return &quot;You &quot;; proposed behaviour will signal an error.<P>
<P>
<P>
<B>Rationale:<P>
</B><P>
It's unlikely that the mention of <A REL=DEFINITION HREF="../Body/f_vec_ps.htm#vector-push"><B>VECTOR-PUSH</B></A> in CLtL p331 was intended<P>
to suggest that characters could be quietly &quot;dropped on the floor&quot;. In<P>
any case, there is no practical or theoretical reason to make <A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> and<P>
<A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A> act differently on non-adjustable strings.<P>
<P>
<P>
<B>Current Practice:<P>
</B><P>
VaxLisp 2.2 and Lucid 3.0 implement the proposal; Lucid 2.1 and earlier<P>
versions implement CLtL. For <A REL=DEFINITION HREF="../Body/m_w_out_.htm#with-output-to-string"><B>WITH-OUTPUT-TO-STRING</B></A>, Xerox Common Lisp <P>
implements CLtL. Symbolics Genera 7.2 implements the proposal.<P>
<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Very small.<P>
<P>
<B>Cost to Users:<P>
</B><P>
Virtually none.<P>
<P>
<P>
<B>Benefits:<P>
</B><P>
Less special-casing in the semantics of &quot;printing&quot; to strings.<P>
More conformity with naive expectations about printing to strings.<P>
<P>
<P>
<B>Aesthetics:<P>
</B><P>
Minor impact.<P>
<P>
<B>Discussion:<P>
</B><P>
Implementations may want to actually call <A REL=DEFINITION HREF="../Body/f_vec_ps.htm#vector-push"><B>VECTOR-PUSH</B></A>, rather than<P>
<A REL=DEFINITION HREF="../Body/f_vec_ps.htm#vector-push-extend"><B>VECTOR-PUSH-EXTEND</B></A>, on non-adjustable string in order to test the<P>
result -- nil means an overflow of the total length of the string; <P>
thus they may signal an error more directly related to the problem,<P>
rather than permitting <A REL=DEFINITION HREF="../Body/f_vec_ps.htm#vector-push-extend"><B>VECTOR-PUSH-EXTEND</B></A> to complain about a non-<P>
adjustable array. But either way, the semantics is still that of<P>
VECTOR-PUSH-EXTEND: when you get to the end of the string, adjustable <P>
strings are extended, and non-adjustable strings cause error signals.<P>
<P>
It's perfectly acceptable to use <A REL=DEFINITION HREF="../Body/f_vec_ps.htm#vector-push-extend"><B>VECTOR-PUSH-EXTEND</B></A> with a non-adjustable<P>
array. It's the error-signalling property of <A REL=DEFINITION HREF="../Body/f_vec_ps.htm#vector-push-extend"><B>VECTOR-PUSH-EXTEND</B></A>, as opposed<P>
to the &quot;dropping on the floor&quot; of <A REL=DEFINITION HREF="../Body/f_vec_ps.htm#vector-push"><B>VECTOR-PUSH</B></A>, that motivated this proposal.<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>