480 lines
10 KiB
HTML
480 lines
10 KiB
HTML
|
<!DOCTYPE HTML>
|
||
|
<HTML LANG="en-us"
|
||
|
><HEAD
|
||
|
><TITLE
|
||
|
>pprint-fill, pprint-linear, pprint-tabular | Common Lisp Nova Spec</TITLE
|
||
|
><META CHARSET="US-ASCII"
|
||
|
><LINK REL="canonical" HREF="f_pprint-fill.html"
|
||
|
><LINK REL="next" HREF="f_pprint-indent.html" TYPE="text/html" TITLE="pprint-indent"
|
||
|
><LINK REL="prev" HREF="f_pprint-exit-if-list-exhausted.html" TYPE="text/html" TITLE="pprint-exit-if-list-exhausted"
|
||
|
><LINK REL="up" HREF="22_4_Printer_Dictionary.html" TYPE="text/html" TITLE="22.4 Printer Dictionary"
|
||
|
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
|
||
|
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
|
||
|
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
|
||
|
><SCRIPT SRC="dpans.js%3F3909942064"
|
||
|
></SCRIPT
|
||
|
><SCRIPT SRC="apropos.js%3F3909942064"
|
||
|
></SCRIPT
|
||
|
></HEAD
|
||
|
><BODY
|
||
|
><DIV
|
||
|
><DIV CLASS="topnav"
|
||
|
><DIV CLASS="breadcrumb"
|
||
|
><SPAN CLASS="breadcrumb-item"
|
||
|
><A HREF="index.html"
|
||
|
>Common Lisp Nova Spec</A
|
||
|
></SPAN
|
||
|
> <SPAN CLASS="breadcrumb-item"
|
||
|
>→ <A HREF="22_Printer.html"
|
||
|
>22. Printer</A
|
||
|
></SPAN
|
||
|
> <SPAN CLASS="breadcrumb-item"
|
||
|
>→ <A HREF="22_4_Printer_Dictionary.html"
|
||
|
>22.4 Printer Dictionary</A
|
||
|
></SPAN
|
||
|
> <SPAN CLASS="breadcrumb-item"
|
||
|
>→ <A HREF="f_pprint-fill.html"
|
||
|
>pprint-fill, pprint-linear, pprint-tabular</A
|
||
|
></SPAN
|
||
|
></DIV
|
||
|
><DIV CLASS="apropos"
|
||
|
><DIV CLASS="apropos-io"
|
||
|
><A HREF="f_pprint-exit-if-list-exhausted.html" CLASS="prev"
|
||
|
>←</A
|
||
|
><SPAN ID="apropos-label"
|
||
|
>Apropos </SPAN
|
||
|
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
|
||
|
><A HREF="f_pprint-indent.html" CLASS="next"
|
||
|
>→</A
|
||
|
></DIV
|
||
|
><DIV ID="apropos-res"
|
||
|
></DIV
|
||
|
></DIV
|
||
|
></DIV
|
||
|
><DIV CLASS="matter"
|
||
|
><DIV CLASS="com"
|
||
|
><DIV CLASS="begincom"
|
||
|
><HR
|
||
|
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
|
||
|
><TR
|
||
|
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
|
||
|
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="pprint-fill, pprint-linear, pprint-tabular"
|
||
|
></SPAN
|
||
|
><B
|
||
|
>pprint-fill, pprint-linear, pprint-tabular</B
|
||
|
></TD
|
||
|
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
|
||
|
><I
|
||
|
>Function</I
|
||
|
></TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
><HR
|
||
|
></DIV
|
||
|
><UL CLASS="subtoc"
|
||
|
></UL
|
||
|
><DL
|
||
|
><DT
|
||
|
><B
|
||
|
>Syntax</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
><B
|
||
|
>pprint-fill</B
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>stream</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>object</SPAN
|
||
|
> <SPAN CLASS="cmtt"
|
||
|
>&optional</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>colon-p</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>at-sign-p</SPAN
|
||
|
> <SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
> <SPAN CLASS="misc"
|
||
|
><B
|
||
|
>nil</B
|
||
|
></SPAN
|
||
|
></P
|
||
|
><P CLASS="j"
|
||
|
><B
|
||
|
>pprint-linear</B
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>stream</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>object</SPAN
|
||
|
> <SPAN CLASS="cmtt"
|
||
|
>&optional</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>colon-p</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>at-sign-p</SPAN
|
||
|
> <SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
> <SPAN CLASS="misc"
|
||
|
><B
|
||
|
>nil</B
|
||
|
></SPAN
|
||
|
></P
|
||
|
><P CLASS="j"
|
||
|
><B
|
||
|
>pprint-tabular</B
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>stream</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>object</SPAN
|
||
|
> <SPAN CLASS="cmtt"
|
||
|
>&optional</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>colon-p</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>at-sign-p</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>tabsize</SPAN
|
||
|
> <SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
> <SPAN CLASS="misc"
|
||
|
><B
|
||
|
>nil</B
|
||
|
></SPAN
|
||
|
></P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Arguments and Values</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
><VAR CLASS="param"
|
||
|
>stream</VAR
|
||
|
> — an <A HREF="26_1_Glossary.html#output"
|
||
|
><EM CLASS="term"
|
||
|
>output</EM
|
||
|
></A
|
||
|
> <A HREF="26_1_Glossary.html#stream_designator"
|
||
|
><EM CLASS="term"
|
||
|
>stream designator</EM
|
||
|
></A
|
||
|
>. </P
|
||
|
><P CLASS="j"
|
||
|
><VAR CLASS="param"
|
||
|
>object</VAR
|
||
|
> — an <A HREF="26_1_Glossary.html#object"
|
||
|
><EM CLASS="term"
|
||
|
>object</EM
|
||
|
></A
|
||
|
>. </P
|
||
|
><P CLASS="j"
|
||
|
><VAR CLASS="param"
|
||
|
>colon-p</VAR
|
||
|
> — a <A HREF="26_1_Glossary.html#generalized_boolean"
|
||
|
><EM CLASS="term"
|
||
|
>generalized boolean</EM
|
||
|
></A
|
||
|
>. The default is <A HREF="26_1_Glossary.html#true"
|
||
|
><EM CLASS="term"
|
||
|
>true</EM
|
||
|
></A
|
||
|
>. </P
|
||
|
><P CLASS="j"
|
||
|
><VAR CLASS="param"
|
||
|
>at-sign-p</VAR
|
||
|
> — a <A HREF="26_1_Glossary.html#generalized_boolean"
|
||
|
><EM CLASS="term"
|
||
|
>generalized boolean</EM
|
||
|
></A
|
||
|
>. The default is <A HREF="26_1_Glossary.html#implementation-dependent"
|
||
|
><EM CLASS="term"
|
||
|
>implementation-dependent</EM
|
||
|
></A
|
||
|
>. </P
|
||
|
><P CLASS="j"
|
||
|
><VAR CLASS="param"
|
||
|
>tabsize</VAR
|
||
|
> — a non-negative <A HREF="26_1_Glossary.html#integer"
|
||
|
><EM CLASS="term"
|
||
|
>integer</EM
|
||
|
></A
|
||
|
>. The default is <CODE CLASS="f"
|
||
|
>16</CODE
|
||
|
>.</P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Description</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>The functions <A HREF="f_pprint-fill.html" CLASS="funref"
|
||
|
><B
|
||
|
>pprint-fill</B
|
||
|
></A
|
||
|
>, <A HREF="f_pprint-fill.html" CLASS="funref"
|
||
|
><B
|
||
|
>pprint-linear</B
|
||
|
></A
|
||
|
>, and <A HREF="f_pprint-fill.html" CLASS="funref"
|
||
|
><B
|
||
|
>pprint-tabular</B
|
||
|
></A
|
||
|
> specify particular ways of <A HREF="26_1_Glossary.html#pretty_print"
|
||
|
><EM CLASS="term"
|
||
|
>pretty printing</EM
|
||
|
></A
|
||
|
> a <A HREF="26_1_Glossary.html#list"
|
||
|
><EM CLASS="term"
|
||
|
>list</EM
|
||
|
></A
|
||
|
> to <VAR CLASS="param"
|
||
|
>stream</VAR
|
||
|
>. Each function prints parentheses around the output if and only if <VAR CLASS="param"
|
||
|
>colon-p</VAR
|
||
|
> is <A HREF="26_1_Glossary.html#true"
|
||
|
><EM CLASS="term"
|
||
|
>true</EM
|
||
|
></A
|
||
|
>. Each function ignores its <VAR CLASS="param"
|
||
|
>at-sign-p</VAR
|
||
|
> argument. (Both arguments are included even though only one is needed so that these functions can be used via <SPAN CLASS="cmtt"
|
||
|
>~/.../</SPAN
|
||
|
> and as <A HREF="f_set-pprint-dispatch.html" CLASS="funref"
|
||
|
><B
|
||
|
>set-pprint-dispatch</B
|
||
|
></A
|
||
|
> functions, as well as directly.) Each function handles abbreviation and the detection of circularity and sharing correctly, and uses <A HREF="f_write.html" CLASS="funref"
|
||
|
><B
|
||
|
>write</B
|
||
|
></A
|
||
|
> to print <VAR CLASS="param"
|
||
|
>object</VAR
|
||
|
> when it is a <A HREF="26_1_Glossary.html#non-list"
|
||
|
><EM CLASS="term"
|
||
|
>non-list</EM
|
||
|
></A
|
||
|
>. </P
|
||
|
><P CLASS="j"
|
||
|
>If <VAR CLASS="param"
|
||
|
>object</VAR
|
||
|
> is a <A HREF="26_1_Glossary.html#list"
|
||
|
><EM CLASS="term"
|
||
|
>list</EM
|
||
|
></A
|
||
|
> and if the <A HREF="26_1_Glossary.html#value"
|
||
|
><EM CLASS="term"
|
||
|
>value</EM
|
||
|
></A
|
||
|
> of <A HREF="v_print-pretty.html" CLASS="misc"
|
||
|
><B
|
||
|
>*print-pretty*</B
|
||
|
></A
|
||
|
> is <A HREF="26_1_Glossary.html#false"
|
||
|
><EM CLASS="term"
|
||
|
>false</EM
|
||
|
></A
|
||
|
>, each of these functions prints <VAR CLASS="param"
|
||
|
>object</VAR
|
||
|
> using a minimum of <A HREF="26_1_Glossary.html#whitespace"
|
||
|
><EM CLASS="term"
|
||
|
>whitespace</EM
|
||
|
></A
|
||
|
>, as described in <A HREF="22_1_The_Lisp_Printer.html#sec_22_1_3_5" CLASS="secref"
|
||
|
><SPAN CLASS="cmr"
|
||
|
>Section</SPAN
|
||
|
> <SPAN CLASS="cmr"
|
||
|
>22.1.3.5</SPAN
|
||
|
> <SPAN CLASS="cmr"
|
||
|
>(Printing</SPAN
|
||
|
> <SPAN CLASS="cmr"
|
||
|
>Lists</SPAN
|
||
|
> <SPAN CLASS="cmr"
|
||
|
>and</SPAN
|
||
|
> <SPAN CLASS="cmr"
|
||
|
>Conses)</SPAN
|
||
|
></A
|
||
|
>. Otherwise (if <VAR CLASS="param"
|
||
|
>object</VAR
|
||
|
> is a <A HREF="26_1_Glossary.html#list"
|
||
|
><EM CLASS="term"
|
||
|
>list</EM
|
||
|
></A
|
||
|
> and if the <A HREF="26_1_Glossary.html#value"
|
||
|
><EM CLASS="term"
|
||
|
>value</EM
|
||
|
></A
|
||
|
> of <A HREF="v_print-pretty.html" CLASS="misc"
|
||
|
><B
|
||
|
>*print-pretty*</B
|
||
|
></A
|
||
|
> is <A HREF="26_1_Glossary.html#true"
|
||
|
><EM CLASS="term"
|
||
|
>true</EM
|
||
|
></A
|
||
|
>):</P
|
||
|
><UL
|
||
|
><LI
|
||
|
><P CLASS="j"
|
||
|
>The <A HREF="26_1_Glossary.html#function"
|
||
|
><EM CLASS="term"
|
||
|
>function</EM
|
||
|
></A
|
||
|
> <A HREF="f_pprint-fill.html" CLASS="funref"
|
||
|
><B
|
||
|
>pprint-linear</B
|
||
|
></A
|
||
|
> prints a <A HREF="26_1_Glossary.html#list"
|
||
|
><EM CLASS="term"
|
||
|
>list</EM
|
||
|
></A
|
||
|
> either all on one line, or with each <A HREF="26_1_Glossary.html#element"
|
||
|
><EM CLASS="term"
|
||
|
>element</EM
|
||
|
></A
|
||
|
> on a separate line.</P
|
||
|
></LI
|
||
|
><LI
|
||
|
><P CLASS="j"
|
||
|
>The <A HREF="26_1_Glossary.html#function"
|
||
|
><EM CLASS="term"
|
||
|
>function</EM
|
||
|
></A
|
||
|
> <A HREF="f_pprint-fill.html" CLASS="funref"
|
||
|
><B
|
||
|
>pprint-fill</B
|
||
|
></A
|
||
|
> prints a <A HREF="26_1_Glossary.html#list"
|
||
|
><EM CLASS="term"
|
||
|
>list</EM
|
||
|
></A
|
||
|
> with as many <A HREF="26_1_Glossary.html#element"
|
||
|
><EM CLASS="term"
|
||
|
>elements</EM
|
||
|
></A
|
||
|
> as possible on each line.</P
|
||
|
></LI
|
||
|
><LI
|
||
|
><P CLASS="j"
|
||
|
>The <A HREF="26_1_Glossary.html#function"
|
||
|
><EM CLASS="term"
|
||
|
>function</EM
|
||
|
></A
|
||
|
> <A HREF="f_pprint-fill.html" CLASS="funref"
|
||
|
><B
|
||
|
>pprint-tabular</B
|
||
|
></A
|
||
|
> is the same as <A HREF="f_pprint-fill.html" CLASS="funref"
|
||
|
><B
|
||
|
>pprint-fill</B
|
||
|
></A
|
||
|
> except that it prints the <A HREF="26_1_Glossary.html#element"
|
||
|
><EM CLASS="term"
|
||
|
>elements</EM
|
||
|
></A
|
||
|
> so that they line up in columns. The <VAR CLASS="param"
|
||
|
>tabsize</VAR
|
||
|
> specifies the column spacing in <A HREF="26_1_Glossary.html#em"
|
||
|
><EM CLASS="term"
|
||
|
>ems</EM
|
||
|
></A
|
||
|
>, which is the total spacing from the leading edge of one column to the leading edge of the next.</P
|
||
|
></LI
|
||
|
></UL
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Examples</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>Evaluating the following with a line length of <CODE CLASS="f"
|
||
|
>25</CODE
|
||
|
> produces the output shown.</P
|
||
|
><PRE CLASS="screen"
|
||
|
>(progn (princ "Roads ")
|
||
|
(pprint-tabular *standard-output* '(elm main maple center) nil nil 8))
|
||
|
Roads ELM MAIN
|
||
|
MAPLE CENTER</PRE
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Side Effects</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>Performs output to the indicated <A HREF="26_1_Glossary.html#stream"
|
||
|
><EM CLASS="term"
|
||
|
>stream</EM
|
||
|
></A
|
||
|
>.</P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Affected By</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>The cursor position on the indicated <A HREF="26_1_Glossary.html#stream"
|
||
|
><EM CLASS="term"
|
||
|
>stream</EM
|
||
|
></A
|
||
|
>, if it can be determined.</P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Notes</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>The <A HREF="26_1_Glossary.html#function"
|
||
|
><EM CLASS="term"
|
||
|
>function</EM
|
||
|
></A
|
||
|
> <A HREF="f_pprint-fill.html" CLASS="funref"
|
||
|
><B
|
||
|
>pprint-tabular</B
|
||
|
></A
|
||
|
> could be defined as follows:</P
|
||
|
><PRE CLASS="screen"
|
||
|
>(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
|
||
|
><P CLASS="j"
|
||
|
>Note that it would have been inconvenient to specify this function using <A HREF="f_format.html" CLASS="funref"
|
||
|
><B
|
||
|
>format</B
|
||
|
></A
|
||
|
>, because of the need to pass its <VAR CLASS="param"
|
||
|
>tabsize</VAR
|
||
|
> argument through to a <SPAN CLASS="cmtt"
|
||
|
>~:T</SPAN
|
||
|
> format directive nested within an iteration over a list.</P
|
||
|
></DD
|
||
|
></DL
|
||
|
></DIV
|
||
|
></DIV
|
||
|
><DIV CLASS="footer"
|
||
|
><DIV CLASS="btmnav"
|
||
|
><A HREF="f_pprint-exit-if-list-exhausted.html" CLASS="prev"
|
||
|
>←</A
|
||
|
><A HREF="f_pprint-indent.html" CLASS="next"
|
||
|
>→</A
|
||
|
></DIV
|
||
|
><DIV CLASS="trail"
|
||
|
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
|
||
|
></DIV
|
||
|
></DIV
|
||
|
><SCRIPT
|
||
|
>domReady();</SCRIPT
|
||
|
></BODY
|
||
|
></HTML
|
||
|
>
|