88 lines
5.1 KiB
HTML
88 lines
5.1 KiB
HTML
![]() |
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
||
|
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
||
|
<HEAD>
|
||
|
<TITLE>22.1. Printed Representation of Lisp Objects</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Printed Representation of Lisp Objects">
|
||
|
<meta name="keywords" value="clm">
|
||
|
<meta name="resource-type" value="document">
|
||
|
<meta name="distribution" value="global">
|
||
|
<P>
|
||
|
<b>Common Lisp the Language, 2nd Edition</b>
|
||
|
<BR> <HR><A NAME=tex2html3873 HREF="node188.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3871 HREF="node186.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3865 HREF="node186.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3875 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3876 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html3874 HREF="node188.html"> What the Read </A>
|
||
|
<B>Up:</B> <A NAME=tex2html3872 HREF="node186.html"> Input/Output</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html3866 HREF="node186.html"> Input/Output</A>
|
||
|
<HR> <P>
|
||
|
<H1><A NAME=SECTION002610000000000000000>22.1. Printed Representation of Lisp Objects</A></H1>
|
||
|
<P>
|
||
|
Lisp objects in general are not text strings but complex data structures.
|
||
|
They have very different properties from text strings as a consequence of
|
||
|
their internal representation. However, to make it possible to get at
|
||
|
and talk about Lisp objects, Lisp provides a representation of
|
||
|
most objects in the form of printed text; this is called the <i>printed
|
||
|
representation</i>, which is used for input/output purposes and in the
|
||
|
examples throughout this book. Functions such as <tt>print</tt> take a
|
||
|
Lisp object and send the characters of its printed representation to a
|
||
|
stream. The collection of routines that does this is known as the
|
||
|
(Lisp) <i>printer</i>. The <tt>read</tt> function takes characters from a
|
||
|
stream, interprets them as a printed representation of a Lisp object,
|
||
|
builds that object, and returns it; the collection of routines
|
||
|
that does this is called the (Lisp) <i>reader</i>.
|
||
|
<A NAME=19886> </A>
|
||
|
<A NAME=19887> </A>
|
||
|
<A NAME=19888> </A>
|
||
|
<P>
|
||
|
Ideally, one could print a Lisp object and then read the printed
|
||
|
representation back in, and so obtain the same identical object.
|
||
|
In practice this is difficult and for some purposes not even desirable.
|
||
|
Instead, reading a printed representation produces an object
|
||
|
that is (with obscure technical exceptions)
|
||
|
<tt>equal</tt> to the originally printed object.
|
||
|
<P>
|
||
|
Most Lisp objects have more than one possible printed representation.
|
||
|
For example, the integer twenty-seven can be written in any of these ways:
|
||
|
<P><pre>
|
||
|
27 27. #o33 #x1B #b11011 #.(* 3 3 3) 81/3
|
||
|
</pre><P>
|
||
|
A list of two symbols <tt>A</tt> and <tt>B</tt> can be printed in many ways:
|
||
|
<P><pre>
|
||
|
(A B) (a b) ( a b ) ( A |B|)
|
||
|
(| A|
|
||
|
B
|
||
|
)
|
||
|
</pre><P>
|
||
|
The last example, which is spread over three lines, may be ugly, but it
|
||
|
is legitimate. In general, wherever whitespace is permissible in a printed
|
||
|
representation, any number of spaces and newlines may appear.
|
||
|
<P>
|
||
|
When <tt>print</tt> produces a printed representation, it must choose arbitrarily
|
||
|
from among many possible printed representations. It attempts to choose
|
||
|
one that is readable. There are a number of global variables that can
|
||
|
be used to control the actions of <tt>print</tt>, and a number of different
|
||
|
printing functions.
|
||
|
<P>
|
||
|
This section describes in detail what is the standard printed
|
||
|
representation for any Lisp object and also describes how <tt>read</tt> operates.
|
||
|
<P>
|
||
|
<HR>
|
||
|
<UL>
|
||
|
<LI> <A NAME=tex2html3877 HREF="node188.html#SECTION002611000000000000000"> What the Read Function Accepts</A>
|
||
|
<LI> <A NAME=tex2html3878 HREF="node189.html#SECTION002612000000000000000"> Parsing of Numbers and Symbols</A>
|
||
|
<LI> <A NAME=tex2html3879 HREF="node190.html#SECTION002613000000000000000"> Macro Characters</A>
|
||
|
<LI> <A NAME=tex2html3880 HREF="node191.html#SECTION002614000000000000000"> Standard Dispatching Macro Character Syntax</A>
|
||
|
<LI> <A NAME=tex2html3881 HREF="node192.html#SECTION002615000000000000000"> The Readtable</A>
|
||
|
<LI> <A NAME=tex2html3882 HREF="node193.html#SECTION002616000000000000000"> What the Print Function Produces</A>
|
||
|
</UL>
|
||
|
<BR> <HR><A NAME=tex2html3873 HREF="node188.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3871 HREF="node186.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3865 HREF="node186.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3875 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3876 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html3874 HREF="node188.html"> What the Read </A>
|
||
|
<B>Up:</B> <A NAME=tex2html3872 HREF="node186.html"> Input/Output</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html3866 HREF="node186.html"> Input/Output</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|