Common Lisp the Language, 2nd Edition
Next: What the Read
Up: Input/Output
Previous: Input/Output
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 printed representation, which is used for
input/output purposes and in the examples throughout this book.
Functions such as print
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) printer. The
read
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) reader.
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) equal
to the originally
printed object.
Most Lisp objects have more than one possible printed representation. For example, the integer twenty-seven can be written in any of these ways:
27 27. #o33 #x1B #b11011 #.(* 3 3 3) 81/3
A list of two symbols A
and B
can be
printed in many ways:
(A B) (a b) ( a b ) ( A |B|)
(| A|
B
)
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.
When print
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 print
,
and a number of different printing functions.
This section describes in detail what is the standard printed
representation for any Lisp object and also describes how
read
operates.
Next: What the Read
Up: Input/Output
Previous: Input/Output
AI.Repository@cs.cmu.edu