63 lines
6.4 KiB
HTML
63 lines
6.4 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 22.1.3.5</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="22_acd.htm">
|
||
|
<LINK REL=UP HREF="22_ac.htm">
|
||
|
<LINK REL=NEXT HREF="22_acf.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="22_acd.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="22_ac.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="22_acf.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
||
|
|
||
|
<HR>
|
||
|
|
||
|
<H2>
|
||
|
22.1.3.5 Printing Lists and Conses</H2> <P>
|
||
|
Wherever possible, list notation is preferred over dot notation. Therefore the following algorithm is used to print a <A REL=DEFINITION HREF="26_glo_c.htm#cons"><I>cons</I></A> x: <P>
|
||
|
<P><DL><DT>1. A <A REL=DEFINITION HREF="26_glo_l.htm#left-parenthesis"><I>left-parenthesis</I></A> is printed. <P><DD>
|
||
|
<DT>2. The <A REL=DEFINITION HREF="26_glo_c.htm#car"><I>car</I></A> of x is printed. <P><DD>
|
||
|
<DT>3. If the <A REL=DEFINITION HREF="26_glo_c.htm#cdr"><I>cdr</I></A> of x is itself a <A REL=DEFINITION HREF="26_glo_c.htm#cons"><I>cons</I></A>, it is made to be the current <A REL=DEFINITION HREF="26_glo_c.htm#cons"><I>cons</I></A> (i.e., x becomes that <A REL=DEFINITION HREF="26_glo_c.htm#cons"><I>cons</I></A>), a <A REL=DEFINITION HREF="26_glo_s.htm#space"><I>space</I></A> is printed, and step 2 is re-entered. <P><DD>
|
||
|
<DT>4. If the <A REL=DEFINITION HREF="26_glo_c.htm#cdr"><I>cdr</I></A> of x is not <A REL=DEFINITION HREF="26_glo_n.htm#null"><I>null</I></A>, a <A REL=DEFINITION HREF="26_glo_s.htm#space"><I>space</I></A>, a <A REL=DEFINITION HREF="26_glo_d.htm#dot"><I>dot</I></A>, a <A REL=DEFINITION HREF="26_glo_s.htm#space"><I>space</I></A>, and the <A REL=DEFINITION HREF="26_glo_c.htm#cdr"><I>cdr</I></A> of x are printed. <P><DD>
|
||
|
<DT>5. A <A REL=DEFINITION HREF="26_glo_r.htm#right-parenthesis"><I>right-parenthesis</I></A> is printed. <P><DD></DL><P>
|
||
|
Actually, the above algorithm is only used when <A REL=DEFINITION HREF="v_pr_pre.htm#STprint-prettyST"><B>*print-pretty*</B></A> is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>. When <A REL=DEFINITION HREF="v_pr_pre.htm#STprint-prettyST"><B>*print-pretty*</B></A> is <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> (or when <A REL=DEFINITION HREF="f_wr_pr.htm#pprint"><B>pprint</B></A> is used), additional <A REL=DEFINITION HREF="26_glo_w.htm#whitespace"><I>whitespace</I></A>[1] may replace the use of a single <A REL=DEFINITION HREF="26_glo_s.htm#space"><I>space</I></A>, and a more elaborate algorithm with similar goals but more presentational flexibility is used; see <A REL=CHILD HREF="22_ab.htm">Section 22.1.2 (Printer Dispatching)</A>. <P>
|
||
|
Although the two expressions below are equivalent, and the reader accepts either one and produces the same <A REL=DEFINITION HREF="26_glo_c.htm#cons"><I>cons</I></A>, the printer always prints such a <A REL=DEFINITION HREF="26_glo_c.htm#cons"><I>cons</I></A> in the second form. <P>
|
||
|
<PRE>
|
||
|
(a . (b . ((c . (d . nil)) . (e . nil))))
|
||
|
(a b (c d) e)
|
||
|
</PRE>
|
||
|
</TT> The printing of <A REL=DEFINITION HREF="26_glo_c.htm#cons"><I>conses</I></A> is affected by <A REL=DEFINITION HREF="v_pr_lev.htm#STprint-levelST"><B>*print-level*</B></A>, <A REL=DEFINITION HREF="v_pr_lev.htm#STprint-lengthST"><B>*print-length*</B></A>, and <A REL=DEFINITION HREF="v_pr_cir.htm#STprint-circleST"><B>*print-circle*</B></A>. <P>
|
||
|
Following are examples of printed representations of <A REL=DEFINITION HREF="26_glo_l.htm#list"><I>lists</I></A>: <P>
|
||
|
<PRE>
|
||
|
(a . b) ;A dotted pair of a and b
|
||
|
(a.b) ;A list of one element, the symbol named a.b
|
||
|
(a. b) ;A list of two elements a. and b
|
||
|
(a .b) ;A list of two elements a and .b
|
||
|
(a b . c) ;A dotted list of a and b with c at the end; two conses
|
||
|
.iot ;The symbol whose name is .iot
|
||
|
(. b) ;Invalid -- an error is signaled if an attempt is made to read
|
||
|
;this syntax.
|
||
|
(a .) ;Invalid -- an error is signaled.
|
||
|
(a .. b) ;Invalid -- an error is signaled.
|
||
|
(a . . b) ;Invalid -- an error is signaled.
|
||
|
(a b c ...) ;Invalid -- an error is signaled.
|
||
|
(a \. b) ;A list of three elements a, ., and b
|
||
|
(a |.| b) ;A list of three elements a, ., and b
|
||
|
(a \... b) ;A list of three elements a, ..., and b
|
||
|
(a |...| b) ;A list of three elements a, ..., and b
|
||
|
</PRE>
|
||
|
</TT> <P>
|
||
|
For information on how the <A REL=DEFINITION HREF="26_glo_l.htm#lisp_reader"><I>Lisp reader</I></A> parses <A REL=DEFINITION HREF="26_glo_l.htm#list"><I>lists</I></A> and <A REL=DEFINITION HREF="26_glo_c.htm#cons"><I>conses</I></A>, see <A REL=CHILD HREF="02_da.htm">Section 2.4.1 (Left-Parenthesis)</A>. <P>
|
||
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issue</A>, <I>not part of the specification</I>, applies to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss277.htm">PRINTER-WHITESPACE:JUST-ONE-SPACE</A><P></UL><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>
|