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

224 lines
17 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 PEEK-CHAR-READ-CHAR-ECHO 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/iss267_w.htm">
<LINK REL=UP HREF="../Issues/iss268.htm">
<LINK REL=NEXT HREF="../Issues/iss269_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/iss267_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss268.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss269_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue PEEK-CHAR-READ-CHAR-ECHO Writeup</H2>
<PRE><B>Status:</B> Passed, Jan 89 X3J13<P>
<B>Issue:</B> <A HREF="iss268.htm">PEEK-CHAR-READ-CHAR-ECHO</A><P>
<B>References:</B> <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> (p379), <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> (p379), <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A> (p379),<P>
<A REL=DEFINITION HREF="../Body/f_mk_ech.htm#make-echo-stream"><B>MAKE-ECHO-STREAM</B></A> (p330), Streams (p327-328),<P>
<A REL=DEFINITION HREF="../Body/f_rd_rd.htm#read-preserving-whitespace"><B>READ-PRESERVING-WHITESPACE</B></A> (p376), <P>
<A REL=DEFINITION HREF="../Body/f_rd_del.htm#read-delimited-list"><B>READ-DELIMITED-LIST</B></A> (p377)<P>
<B>Category:</B> CLARIFICATION/CHANGE<P>
<B>Edit history:</B> 06-Mar-87, Version 1 by Pitman<P>
23-Jun-88, Version 2 by Pitman (remove interactive stuff)<P>
8-Oct-88, Version 3 by Pitman &amp; Masinter<P>
<P>
<B>Problem Description:<P>
</B><P>
The interaction between <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A>, <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> and streams made by<P>
<A REL=DEFINITION HREF="../Body/f_mk_ech.htm#make-echo-stream"><B>MAKE-ECHO-STREAM</B></A> is not made adequately clear about how many times<P>
a particular character may be echoed and at what time such echo<P>
is permissible.<P>
<P>
For example, given:<P>
(<A REL=DEFINITION HREF="../Body/m_w_in_f.htm#with-input-from-string"><B>WITH-INPUT-FROM-STRING</B></A> (<A REL=DEFINITION HREF="../Body/t_stg_st.htm#string-stream"><B>STRING-STREAM</B></A> &quot;A&quot;)<P>
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> ((<A REL=DEFINITION HREF="../Body/v_debug_.htm#STstandard-inputST"><B>*STANDARD-INPUT*</B></A> (<A REL=DEFINITION HREF="../Body/f_mk_ech.htm#make-echo-stream"><B>MAKE-ECHO-STREAM</B></A> <A REL=DEFINITION HREF="../Body/t_stg_st.htm#string-stream"><B>STRING-STREAM</B></A><P>
<A REL=DEFINITION HREF="../Body/v_debug_.htm#STstandard-outputST"><B>*STANDARD-OUTPUT*</B></A>)))<P>
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> ((<A REL=DEFINITION HREF="../Body/f_char_.htm#char"><B>CHAR</B></A> <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>))<P>
(<A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A>) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>PRIN1</B></A> '---)<P>
(<A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A>) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>PRIN1</B></A> '---)<P>
(<A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>SETQ</B></A> <A REL=DEFINITION HREF="../Body/f_char_.htm#char"><B>CHAR</B></A> (<A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A>)) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>PRIN1</B></A> '---)<P>
(<A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> <A REL=DEFINITION HREF="../Body/f_char_.htm#char"><B>CHAR</B></A>) (<A REL=DEFINITION HREF="../Body/f_wr_pr.htm#prin1"><B>PRIN1</B></A> '---)<P>
(<A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A>))))<P>
what is seen on the terminal? There are at least these possibilities:<P>
<P>
[1] <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A> is implemented by READ-CHAR/UNREAD-CHAR. The first time<P>
a char is seen by <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> it's echoed, <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> does not echo,<P>
re-fetching the char by <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> doesn't echo.<P>
A------------<P>
<P>
[2] Characters are echoed whenever seen by <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A> or <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A>.<P>
Characters are not unechoed by <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A>.<P>
A---A---A---A---<P>
<P>
[3] Characters are not echoed by <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A> but are echoed by <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A>.<P>
No `unecho' action is done by <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A>.<P>
------A------A<P>
<P>
[4] <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A> is implemented by READ-CHAR/UNREAD-CHAR. <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> echoes<P>
but <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> does not `unecho'.<P>
A---A---A------A<P>
<P>
[5] <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A> is implemented by READ-CHAR/UNREAD-CHAR. <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> echoes<P>
but <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> unechoes (a magic Erase character must be <P>
presupposed for display terminals, a file stream that can randomly<P>
access during output and/or back up must be presupposed for files,<P>
paper terminals just lose):<P>
A&lt;Erase&gt;---A&lt;Erase&gt;---A---&lt;Erase&gt;---A<P>
<P>
[6] <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A> is implemented by peeking and does not echo. The first<P>
time a char is seen by <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> it's echoed, <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> does not<P>
echo, re-fetching the char by <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> doesn't echo:<P>
------A------<P>
<P>
This list is not believed to be exhaustive. It is only to illustrate<P>
of the variety of possible ways in which the current specification can <P>
be implemented without technically being in conflict with the written <P>
word of CLtL. Obviously not all of these interpretations are considered <P>
useful by all people, but usefulness has not been determined to be <P>
criterial in satisfying the specification.<P>
<P>
The description of streams (p327-328) is also [probably deliberately]<P>
fuzzy on this issue as it relates to operating systems on which echoing <P>
is done by the operating system. That is, some systems are line-at-a-time<P>
and all <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> and <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A> operations happen after issues of echo<P>
have long since been resolved by a system call that reads and echoes input <P>
a line at a time. Other systems are character-at-a-time and these issues <P>
hit home in a different way. It will probably be necessary to continue<P>
leaving things slightly unspecified in order to accomodate the native <P>
style of the variety of operating systems now trying to support Common <P>
Lisp, but we should be more up front about the game we are playing. (For<P>
example, code which must port between character-at-a-time and <P>
line-at-a-time systems must be more careful about whether it does <P>
newline-preceded or newline-terminated output than many CL programmers <P>
might realize given the current wording.) Additionally, though, we should<P>
be on the lookout for less ambitious goals involving only partial<P>
compatibility to improve the situation wherever we can find a way to.<P>
<P>
Abstract functions <A REL=DEFINITION HREF="../Body/f_rd_rd.htm#read-preserving-whitespace"><B>READ-PRESERVING-WHITESPACE</B></A> and <A REL=DEFINITION HREF="../Body/f_rd_del.htm#read-delimited-list"><B>READ-DELIMITED-LIST</B></A><P>
are implicitly affected by any decisions made on this issue since their<P>
descriptions involve the use of <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> and <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A>, respectively.<P>
<P>
<B>Proposal (PEEK-CHAR-READ-CHAR-ECHO:FIRST-READ-CHAR):<P>
</B><P>
Ammend the description of <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> to say that when the stream is<P>
an echo stream (a stream created by <A REL=DEFINITION HREF="../Body/f_mk_ech.htm#make-echo-stream"><B>MAKE-ECHO-STREAM</B></A>), the character<P>
will be echoed on the stream the first time those characters are seen.<P>
(Characters which are <A REL=DEFINITION HREF="../Body/a_not.htm#not"><B>not</B></A> echoed by <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> are those which were<P>
put there by <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> <A REL=DEFINITION HREF="../Body/a_and.htm#and"><B>and</B></A> hence are assumed to have been echoed<P>
already by a previous call to <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A>.)<P>
<P>
Ammend the description of <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> to say that when the stream<P>
is an echo stream (a stream created by <A REL=DEFINITION HREF="../Body/f_mk_ech.htm#make-echo-stream"><B>MAKE-ECHO-STREAM</B></A>), no attempt<P>
will be made to undo any echoing of the character which might already<P>
have been done on the stream. However, characters placed on the<P>
stream by <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> will be marked in such as way as to inhibit<P>
later re-echo by <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A>.<P>
<P>
Ammend the description of <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A> to say that when the stream is<P>
an echo stream (a stream created by <A REL=DEFINITION HREF="../Body/f_mk_ech.htm#make-echo-stream"><B>MAKE-ECHO-STREAM</B></A>), characters<P>
which are only peeked at are not echoed. Note however that in the<P>
case that the PEEK-TYPE argument is not <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>, the characters which<P>
are passed by <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A> are treated as if by <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A>, and so are<P>
echoed unless they have been marked otherwise by <A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A>.<P>
<P>
Ammend the description of abstract input functions <P>
<A REL=DEFINITION HREF="../Body/f_rd_rd.htm#read-preserving-whitespace"><B>READ-PRESERVING-WHITESPACE</B></A> and <A REL=DEFINITION HREF="../Body/f_rd_del.htm#read-delimited-list"><B>READ-DELIMITED-LIST</B></A> to acknowledge<P>
that they are implicitly affected by these new echoing rules of <P>
<A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A>, <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A>, and <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A>.<P>
<P>
Note: This is consistent with behavior [6] in the problem description.<P>
<P>
Clarify that the echo behavior of interactive streams such as<P>
<A REL=DEFINITION HREF="../Body/v_termin.htm#STterminal-ioST"><B>*TERMINAL-IO*</B></A> continues to be implementation dependent.<P>
<P>
<B>Rationale:<P>
</B><P>
Although this is not known to be in use in any particular system,<P>
nothing prevents its use. It proposes a more rational interpretation<P>
of the echoing behavior of <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A> which might make it possible<P>
for programmers concerned about echo behavior not to have to shy<P>
away from <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A>. (It would probably also improve the behavior<P>
of <A REL=DEFINITION HREF="../Body/f_rd_rd.htm#read-preserving-whitespace"><B>READ-PRESERVING-WHITESPACE</B></A> with regard to echoing, since its<P>
description mentions using <A REL=DEFINITION HREF="../Body/f_unrd_c.htm#unread-char"><B>UNREAD-CHAR</B></A>.)<P>
<P>
Correct echoing behavior is important to programs which do batch<P>
processing, parsing, etc. Allowing multiple or premature echoing<P>
is clearly unsatisfactory.<P>
<P>
<B>Current Practice:<P>
</B><P>
A wide variety of behaviors are in use.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Unknown.<P>
<P>
The code to implement the proposed change itself is probably fairly<P>
localized.<P>
<P>
In some operating systems, there may be echoing constraints which<P>
are overlooked here. <P>
<P>
In some cases, there may be second order effects in the system <P>
itself which would also <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A> a somewhat less predictable amount <P>
of work to fix. <P>
<P>
<B>Cost to Users:<P>
</B><P>
Any change is effectively upward compatible since the previous<P>
behavior is so ill-specified.<P>
<P>
Most users probably naively expect (perhaps even without realizing<P>
it explicitly) that echoing will take care of itself. That is, they<P>
probably expect that echoing will occur at the time of the<P>
<A REL=DEFINITION HREF="../Body/f_rd_cha.htm#read-char"><B>READ-CHAR</B></A> and probably do not give a lot of thought to the effect<P>
of <A REL=DEFINITION HREF="../Body/f_peek_c.htm#peek-char"><B>PEEK-CHAR</B></A>. As such, FIRST-READ-CHAR probably best supports most <P>
of their naive intuitions.<P>
<P>
<B>Cost of Non-Adoption:<P>
</B><P>
The streams returned by <A REL=DEFINITION HREF="../Body/f_mk_ech.htm#make-echo-stream"><B>MAKE-ECHO-STREAM</B></A> would continue to be<P>
significantly hard to use portably.<P>
<P>
<B>Benefits:<P>
</B><P>
A number of applications involving of parsers, batch script<P>
interpreters, and such would be possible to implement<P>
straightforwardly and portably.<P>
<P>
<B>Aesthetics:<P>
</B><P>
?<P>
<P>
<B>Discussion:<P>
</B><P>
Pitman supports <A HREF="iss268.htm">PEEK-CHAR-READ-CHAR-ECHO:FIRST-READ-CHAR</A> because<P>
he feels it is more practically coherent. However, he says he has<P>
only mental exercises and no actual personal experience upon which<P>
to base that belief.<P>
<P>
Version 1 of this proposal treated interactive streams on par<P>
with echo streams, but while people agreed that this issue is<P>
a severe portability problem, some considered that the treatment<P>
of interactive streams got involved in operating system issues<P>
that were beyond the scope of the <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A>, so that part of the<P>
text was removed.<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>