1
0
Fork 0
cl-sites/novaspec.org/cl/f_unread-char.html
2025-02-05 18:52:26 +01:00

330 lines
No EOL
6.9 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>unread-char | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_unread-char.html"
><LINK REL="next" HREF="f_write-char.html" TYPE="text/html" TITLE="write-char"
><LINK REL="prev" HREF="f_terpri.html" TYPE="text/html" TITLE="terpri, fresh-line"
><LINK REL="up" HREF="21_2_Streams_Dictionary.html" TYPE="text/html" TITLE="21.2 Streams Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="21_Streams.html"
>21. Streams</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="21_2_Streams_Dictionary.html"
>21.2 Streams Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_unread-char.html"
>unread-char</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_terpri.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_write-char.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="unread-char"
></SPAN
><B
>unread-char</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Function</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>unread-char</B
> <SPAN CLASS="cmssi"
>character</SPAN
> <SPAN CLASS="cmtt"
>&amp;optional</SPAN
> <SPAN CLASS="cmssi"
>input-stream</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="misc"
><B
>nil</B
></SPAN
></P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>character</VAR
> &#8212; a <A HREF="26_1_Glossary.html#character"
><EM CLASS="term"
>character</EM
></A
>; must be the last <A HREF="26_1_Glossary.html#character"
><EM CLASS="term"
>character</EM
></A
> that was read from <VAR CLASS="param"
>input-stream</VAR
>. </P
><P CLASS="j"
><VAR CLASS="param"
>input-stream</VAR
> &#8212; an <A HREF="26_1_Glossary.html#input"
><EM CLASS="term"
>input</EM
></A
> <A HREF="26_1_Glossary.html#stream_designator"
><EM CLASS="term"
>stream designator</EM
></A
>. The default is <A HREF="26_1_Glossary.html#standard_input"
><EM CLASS="term"
>standard input</EM
></A
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_unread-char.html" CLASS="funref"
><B
>unread-char</B
></A
> places <VAR CLASS="param"
>character</VAR
> back onto the front of <VAR CLASS="param"
>input-stream</VAR
> so that it will again be the next character in <VAR CLASS="param"
>input-stream</VAR
>. </P
><P CLASS="j"
>When <VAR CLASS="param"
>input-stream</VAR
> is an <A HREF="26_1_Glossary.html#echo_stream"
><EM CLASS="term"
>echo stream</EM
></A
>, no attempt is made to undo any echoing of the character that might already have been done on <VAR CLASS="param"
>input-stream</VAR
>. However, characters placed on <VAR CLASS="param"
>input-stream</VAR
> by <A HREF="f_unread-char.html" CLASS="funref"
><B
>unread-char</B
></A
> are marked in such a way as to inhibit later re-echo by <A HREF="f_read-char.html" CLASS="funref"
><B
>read-char</B
></A
>. </P
><P CLASS="j"
>It is an error to invoke <A HREF="f_unread-char.html" CLASS="funref"
><B
>unread-char</B
></A
> twice consecutively on the same <A HREF="26_1_Glossary.html#stream"
><EM CLASS="term"
>stream</EM
></A
> without an intervening call to <A HREF="f_read-char.html" CLASS="funref"
><B
>read-char</B
></A
> (or some other input operation which implicitly reads characters) on that <A HREF="26_1_Glossary.html#stream"
><EM CLASS="term"
>stream</EM
></A
>. </P
><P CLASS="j"
>Invoking <A HREF="f_peek-char.html" CLASS="funref"
><B
>peek-char</B
></A
> or <A HREF="f_read-char.html" CLASS="funref"
><B
>read-char</B
></A
> commits all previous characters. The consequences of invoking <A HREF="f_unread-char.html" CLASS="funref"
><B
>unread-char</B
></A
> on any character preceding that which is returned by <A HREF="f_peek-char.html" CLASS="funref"
><B
>peek-char</B
></A
> (including those passed over by <A HREF="f_peek-char.html" CLASS="funref"
><B
>peek-char</B
></A
> that has a <A HREF="26_1_Glossary.html#non-nil"
><EM CLASS="term"
>non-nil</EM
></A
> <VAR CLASS="param"
>peek-type</VAR
>) are unspecified. In particular, the consequences of invoking <A HREF="f_unread-char.html" CLASS="funref"
><B
>unread-char</B
></A
> after <A HREF="f_peek-char.html" CLASS="funref"
><B
>peek-char</B
></A
> are unspecified.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (with-input-from-string (is "0123")
(dotimes (i 6)
(let ((c (read-char is)))
(if (evenp i) (format t "~&amp;~S ~S~%" i c) (unread-char c is)))))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> 0 #\0
<SPAN CLASS="cmr"
>&#8883;</SPAN
> 2 #\1
<SPAN CLASS="cmr"
>&#8883;</SPAN
> 4 #\2
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> NIL</PRE
></DD
><DT
><B
>Affected By</B
></DT
><DD
><P CLASS="j"
><A HREF="v_debug-io.html" CLASS="varref"
><B
>*standard-input*</B
></A
>, <A HREF="v_terminal-io.html" CLASS="varref"
><B
>*terminal-io*</B
></A
>.</P
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_peek-char.html" CLASS="funref"
><B
>peek-char</B
></A
>, <A HREF="f_read-char.html" CLASS="funref"
><B
>read-char</B
></A
>, <A HREF="21_1_Stream_Concepts.html#sec_21_1" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>21.1</SPAN
> <SPAN CLASS="cmr"
>(Stream</SPAN
> <SPAN CLASS="cmr"
>Concepts)</SPAN
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
><A HREF="f_unread-char.html" CLASS="funref"
><B
>unread-char</B
></A
> is intended to be an efficient mechanism for allowing the <A HREF="26_1_Glossary.html#Lisp_reader"
><EM CLASS="term"
>Lisp reader</EM
></A
> and other parsers to perform one-character lookahead in <VAR CLASS="param"
>input-stream</VAR
>.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_terpri.html" CLASS="prev"
>&#8592;</A
><A HREF="f_write-char.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>