1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>pprint-fill (ANSI and GNU Common Lisp Document)</title>
<meta name="description" content="pprint-fill (ANSI and GNU Common Lisp Document)">
<meta name="keywords" content="pprint-fill (ANSI and GNU Common Lisp Document)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Printer-Dictionary.html" rel="up" title="Printer Dictionary">
<link href="pprint_002dindent.html" rel="next" title="pprint-indent">
<link href="pprint_002dexit_002dif_002dlist_002dexhausted.html" rel="prev" title="pprint-exit-if-list-exhausted">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<span id="pprint_002dfill"></span><div class="header">
<p>
Next: <a href="pprint_002dindent.html" accesskey="n" rel="next">pprint-indent</a>, Previous: <a href="pprint_002dexit_002dif_002dlist_002dexhausted.html" accesskey="p" rel="prev">pprint-exit-if-list-exhausted</a>, Up: <a href="Printer-Dictionary.html" accesskey="u" rel="up">Printer Dictionary</a> </p>
</div>
<hr>
<span id="pprint_002dfill_002c-pprint_002dlinear_002c-pprint_002dtabular-_005bFunction_005d"></span><h4 class="subsection">22.4.5 pprint-fill, pprint-linear, pprint-tabular [Function]</h4>
<p><code>pprint-fill</code> <i>stream object <span class="roman">&optional</span> colon-p at-sign-p</i> ⇒ <i><b>nil</b></i>
</p>
<p><code>pprint-linear</code> <i>stream object <span class="roman">&optional</span> colon-p at-sign-p</i> ⇒ <i><b>nil</b></i>
</p>
<p><code>pprint-tabular</code> <i>stream object <span class="roman">&optional</span> colon-p at-sign-p tabsize</i> ⇒ <i><b>nil</b></i>
</p>
<span id="Arguments-and-Values_003a_003a-458"></span><h4 class="subsubheading">Arguments and Values::</h4>
<p><i>stream</i>—an <i>output</i> <i>stream designator</i>.
</p>
<p><i>object</i>—an <i>object</i>.
</p>
<p><i>colon-p</i>—a <i>generalized boolean</i>.
The default is <i>true</i>.
</p>
<p><i>at-sign-p</i>—a <i>generalized boolean</i>.
The default is <i>implementation-dependent</i>.
</p>
<p><i>tabsize</i>—a non-negative <i>integer</i>.
The default is <tt>16</tt>.
</p>
<span id="Description_003a_003a-593"></span><h4 class="subsubheading">Description::</h4>
<p>The functions <b>pprint-fill</b>, <b>pprint-linear</b>, and
<b>pprint-tabular</b> specify particular ways of <i>pretty printing</i>
a <i>list</i> to <i>stream</i>.
Each function prints parentheses around the output if and only
if <i>colon-p</i> is <i>true</i>.
Each function ignores its <i>at-sign-p</i> argument.
(Both arguments are included even though only one is needed
so that these functions can be used via <tt>~/.../</tt>
and as <b>set-pprint-dispatch</b> functions, as well as directly.)
Each function handles abbreviation and the detection of circularity
and sharing correctly, and uses <b>write</b> to print <i>object</i>
when it is a <i>non-list</i>.
</p>
<p>If <i>object</i> is a <i>list</i> and
if the <i>value</i> of <b>*print-pretty*</b> is <i>false</i>,
each of these functions prints <i>object</i>
using a minimum of <i>whitespace</i>,
as described in <a href="Printing-Lists-and-Conses.html">Printing Lists and Conses</a>.
Otherwise (if <i>object</i> is a <i>list</i> and
if the <i>value</i> of <b>*print-pretty*</b> is <i>true</i>):
</p>
<dl compact="compact">
<dt><tt>*</tt></dt>
<dd><p>The <i>function</i> <b>pprint-linear</b> prints a <i>list</i> either all on one line,
or with each <i>element</i> on a separate line.
</p>
</dd>
<dt><tt>*</tt></dt>
<dd><p>The <i>function</i> <b>pprint-fill</b> prints a <i>list</i> with as many <i>elements</i>
as possible on each line.
</p>
</dd>
<dt><tt>*</tt></dt>
<dd><p>The <i>function</i> <b>pprint-tabular</b> is the same as <b>pprint-fill</b>
except that it prints the <i>elements</i> so that they line up in columns.
The <i>tabsize</i> specifies the column spacing in <i>ems</i>,
which is the total spacing from the leading edge of one column to
the leading edge of the next.
</p></dd>
</dl>
<span id="Examples_003a_003a-429"></span><h4 class="subsubheading">Examples::</h4>
<p>Evaluating the following with a line length of <tt>25</tt> produces the output shown.
</p>
<div class="example">
<pre class="example">(progn (princ "Roads ")
(pprint-tabular *standard-output* '(elm main maple center) nil nil 8))
Roads ELM MAIN
MAPLE CENTER
</pre></div>
<span id="Side-Effects_003a_003a-75"></span><h4 class="subsubheading">Side Effects::</h4>
<p>Performs output to the indicated <i>stream</i>.
</p>
<span id="Affected-By_003a_003a-98"></span><h4 class="subsubheading">Affected By::</h4>
<p>The cursor position on the indicated <i>stream</i>, if it can be determined.
</p>
<span id="Notes_003a_003a-299"></span><h4 class="subsubheading">Notes::</h4>
<p>The <i>function</i> <b>pprint-tabular</b> could be defined as follows:
</p>
<div class="example">
<pre class="example">(defun pprint-tabular (s list &optional (colon-p t) at-sign-p (tabsize nil))
(declare (ignore at-sign-p))
(when (null tabsize) (setq tabsize 16))
(pprint-logical-block (s list :prefix (if colon-p "(" "")
:suffix (if colon-p ")" ""))
(pprint-exit-if-list-exhausted)
(loop (write (pprint-pop) :stream s)
(pprint-exit-if-list-exhausted)
(write-char #\Space s)
(pprint-tab :section-relative 0 tabsize s)
(pprint-newline :fill s))))
</pre></div>
<p>Note that it would have been inconvenient to specify this function
using <b>format</b>, because of the need to pass its <i>tabsize</i> argument
through to a <tt>~:T</tt> format directive nested within an iteration over a list.
</p>
<hr>
<div class="header">
<p>
Next: <a href="pprint_002dindent.html" accesskey="n" rel="next">pprint-indent</a>, Previous: <a href="pprint_002dexit_002dif_002dlist_002dexhausted.html" accesskey="p" rel="prev">pprint-exit-if-list-exhausted</a>, Up: <a href="Printer-Dictionary.html" accesskey="u" rel="up">Printer Dictionary</a> </p>
</div>
</body>
</html>
|