Common Lisp the Language, 2nd Edition
Next: Dynamic Control of
Up: Pretty Printing
Previous: Introduction
The function write
accepts keyword arguments named
:pprint-dispatch
, :miser-width
,
:right-margin
, and :lines
, corresponding to
these variables.
[Variable]
*print-pprint-dispatch*
When *print-pretty*
is not nil
, printing is
controlled by the `pprint dispatch table’ stored in the variable
*print-pprint-dispatch*
. The initial value of
*print-pprint-dispatch*
is implementation-dependent and
causes traditional pretty printing of Lisp code. The last section of
this chapter explains how the contents of this table can be changed.
[Variable]
*print-right-margin*
A primary goal of pretty printing is to keep the output between a pair of margins. The left margin is set at the column where the output begins. If this cannot be determined, the left margin is set to zero.
When *print-right-margin*
is not nil
, it
specifies the right margin to use when making layout decisions. When
*print-right-margin*
is nil
(the initial
value), the right margin is set at the maximum line length that can be
displayed by the output stream without wraparound or truncation. If this
cannot be determined, the right margin is set to an
implementation-dependent value.
To allow for the possibility of variable-width fonts,
*print-right-margin*
is in units of ems-the width of an
``m’’ in the font being used to display characters on the relevant
output stream at the moment when the variables are consulted.
[Variable]
*print-miser-width*
If *print-miser-width*
is not nil
, the
pretty printer switches to a compact style of output (called miser
style) whenever the width available for printing a substructure is less
than or equal to *print-miser-width*
ems. The initial value
of *print-miser-width*
is implementation-dependent.
[Variable]
*print-lines*
When given a value other than its initial value of nil
,
*print-lines*
limits the number of output lines produced
when something is pretty printed. If an attempt is made to go beyond
*print-lines*
lines, ``..
’’ (a space and two
periods) is printed at the end of the last line followed by all of the
suffixes (closing delimiters) that are pending to be printed.
(let ((*print-right-margin* 25) (*print-lines* 3))
(pprint '(progn (setq a 1 b 2 c 3 d 4))))
(PROGN (SETQ A 1
B 2
C 3 ..))
(The symbol ``..
’’ is printed out to ensure that a
reader error will occur if the output is later read. A symbol different
from ``...
’’ is used to indicate that a different kind of
abbreviation has occurred.)
Next: Dynamic Control of
Up: Pretty Printing
Previous: Introduction
AI.Repository@cs.cmu.edu