52 lines
6.2 KiB
HTML
52 lines
6.2 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: Section 23.1.3.2</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="23_aca.htm">
|
|
<LINK REL=UP HREF="23_ac.htm">
|
|
<LINK REL=NEXT HREF="c_reader.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="23_aca.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="23_ac.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="c_reader.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<H2>
|
|
23.1.3.2 The RECURSIVE-P argument</H2> <P>
|
|
If <I>recursive-p</I> is supplied and not <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, it specifies that this function call is not an outermost call to <A REL=DEFINITION HREF="f_rd_rd.htm#read"><B>read</B></A> but an embedded call, typically from a <A REL=DEFINITION HREF="26_glo_r.htm#reader_macro_function"><I>reader macro function</I></A>. It is important to distinguish such recursive calls for three reasons. <P>
|
|
<P><DL><DT>1. An outermost call establishes the context within which the <TT>#</TT><I>n</I><TT>=</TT> and <TT>#</TT><I>n</I><TT>#</TT> syntax is scoped. Consider, for example, the expression <P><DD>
|
|
<PRE>
|
|
(cons '#3=(p q r) '(x y . #3#))
|
|
</PRE>
|
|
</TT> If the <A REL=DEFINITION HREF="26_glo_s.htm#single-quote"><I>single-quote</I></A> <A REL=DEFINITION HREF="26_glo_r.htm#reader_macro"><I>reader macro</I></A> were defined in this way: <P>
|
|
<PRE>
|
|
(set-macro-character #\' ;incorrect
|
|
#'(lambda (stream char)
|
|
(declare (ignore char))
|
|
(list 'quote (read stream))))
|
|
</PRE>
|
|
</TT> <P>
|
|
then each call to the <A REL=DEFINITION HREF="26_glo_s.htm#single-quote"><I>single-quote</I></A> <A REL=DEFINITION HREF="26_glo_r.htm#reader_macro_function"><I>reader macro function</I></A> would establish independent contexts for the scope of <A REL=DEFINITION HREF="f_rd_rd.htm#read"><B>read</B></A> information, including the scope of identifications between markers like ``<TT>#3=</TT>'' and ``<TT>#3#</TT>''. However, for this expression, the scope was clearly intended to be determined by the outer set of parentheses, so such a definition would be incorrect. The correct way to define the <A REL=DEFINITION HREF="26_glo_s.htm#single-quote"><I>single-quote</I></A> <A REL=DEFINITION HREF="26_glo_r.htm#reader_macro"><I>reader macro</I></A> uses <I>recursive-p</I>: <P>
|
|
<PRE>
|
|
(set-macro-character #\' ;correct
|
|
#'(lambda (stream char)
|
|
(declare (ignore char))
|
|
(list 'quote (read stream t nil t))))
|
|
</PRE>
|
|
</TT> <P>
|
|
<DT>2. A recursive call does not alter whether the reading process is to preserve <A REL=DEFINITION HREF="26_glo_w.htm#whitespace"><I>whitespace</I></A>[2] or not (as determined by whether the outermost call was to <A REL=DEFINITION HREF="f_rd_rd.htm#read"><B>read</B></A> or <A REL=DEFINITION HREF="f_rd_rd.htm#read-preserving-whitespace"><B>read-preserving-whitespace</B></A>). Suppose again that <A REL=DEFINITION HREF="26_glo_s.htm#single-quote"><I>single-quote</I></A> were to be defined as shown above in the incorrect definition. Then a call to <A REL=DEFINITION HREF="f_rd_rd.htm#read-preserving-whitespace"><B>read-preserving-whitespace</B></A> that read the expression <TT>'foo<Space></TT> would fail to preserve the space character following the symbol <TT>foo</TT> because the <A REL=DEFINITION HREF="26_glo_s.htm#single-quote"><I>single-quote</I></A> <A REL=DEFINITION HREF="26_glo_r.htm#reader_macro_function"><I>reader macro function</I></A> calls <A REL=DEFINITION HREF="f_rd_rd.htm#read"><B>read</B></A>, not <A REL=DEFINITION HREF="f_rd_rd.htm#read-preserving-whitespace"><B>read-preserving-whitespace</B></A>, to read the following expression (in this case <TT>foo</TT>). The correct definition, which passes the value <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> for <I>recursive-p</I> to <A REL=DEFINITION HREF="f_rd_rd.htm#read"><B>read</B></A>, allows the outermost call to determine whether <A REL=DEFINITION HREF="26_glo_w.htm#whitespace"><I>whitespace</I></A>[2] is preserved. <P><DD>
|
|
<DT>3. When end-of-file is encountered and the <I>eof-error-p</I> argument is not <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, the kind of error that is signaled may depend on the value of <I>recursive-p</I>. If <I>recursive-p</I> is <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A>, then the end-of-file is deemed to have occurred within the middle of a printed representation; if <I>recursive-p</I> is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>, then the end-of-file may be deemed to have occurred between <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> rather than within the middle of one. <P><DD>
|
|
<P></DL><P>
|
|
<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>
|