217 lines
125 KiB
HTML
217 lines
125 KiB
HTML
|
<!doctype html>
|
|||
|
<html lang="en" dir="ltr" class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-chap-22/cc-b-the-lisp-printer" data-has-hydrated="false">
|
|||
|
<head>
|
|||
|
<meta charset="UTF-8">
|
|||
|
<meta name="generator" content="Docusaurus v3.0.1">
|
|||
|
<title data-rh="true">22.1 The Lisp Printer | Common Lisp (New) Language Reference</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:image" content="https://lisp-docs.github.io/cl-language-reference/img/1024px-Lisp_logo.svg.png"><meta data-rh="true" name="twitter:image" content="https://lisp-docs.github.io/cl-language-reference/img/1024px-Lisp_logo.svg.png"><meta data-rh="true" property="og:url" content="https://lisp-docs.github.io/cl-language-reference/chap-22/cc-b-the-lisp-printer"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="google-site-verification" content="Vzaw013_bfdKeUVG89Ch3W1zC9_vH9ID2dPB9Dz0vr0"><meta data-rh="true" name="docusaurus_version" content="current"><meta data-rh="true" name="docusaurus_tag" content="docs-default-current"><meta data-rh="true" name="docsearch:version" content="current"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-current"><meta data-rh="true" property="og:title" content="22.1 The Lisp Printer | Common Lisp (New) Language Reference"><meta data-rh="true" name="description" content="22.1.1 Overview of The Lisp Printer"><meta data-rh="true" property="og:description" content="22.1.1 Overview of The Lisp Printer"><link data-rh="true" rel="icon" href="../img/favicon.ico"><link data-rh="true" rel="canonical" href="cc-b-the-lisp-printer.html"><link data-rh="true" rel="alternate" href="cc-b-the-lisp-printer.html" hreflang="en"><link data-rh="true" rel="alternate" href="cc-b-the-lisp-printer.html" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://C1F2Q5VM6X-dsn.algolia.net" crossorigin="anonymous"><link rel="preconnect" href="https://www.google-analytics.com">
|
|||
|
<link rel="preconnect" href="https://www.googletagmanager.com">
|
|||
|
<script async src="https://www.googletagmanager.com/gtag/js?id=G-8TJCE4NSF8"></script>
|
|||
|
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-8TJCE4NSF8",{})</script>
|
|||
|
|
|||
|
|
|||
|
<link rel="search" type="application/opensearchdescription+xml" title="Common Lisp (New) Language Reference" href="../opensearch.xml"><link rel="stylesheet" href="../assets/css/styles.f13b59fe.css">
|
|||
|
<script src="../assets/js/runtime~main.02699c25.js" defer="defer"></script>
|
|||
|
<script src="../assets/js/main.4f0a7a76.js" defer="defer"></script>
|
|||
|
</head>
|
|||
|
<body class="navigation-with-keyboard">
|
|||
|
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return localStorage.getItem("theme")}catch(t){}}();t(null!==e?e:"light")}(),function(){try{const c=new URLSearchParams(window.location.search).entries();for(var[t,e]of c)if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id="__docusaurus"><div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="cc-b-the-lisp-printer.html#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a href="../../index.html" target="_blank" rel="noopener noreferrer" class="navbar__brand"><div class="navbar__logo"><img src="../img/logo.svg" alt="Lisp Logo" class="themedComponent_mlkZ themedComponent--light_NVdE"><img src="../img/logo.svg" alt="Lisp Logo" class="themedComponent_mlkZ themedComponent--dark_xIcU"></div><b class="navbar__title text--truncate">Common Lisp Docs</b></a><a href="../../docs/tutorial/index.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Tutorial</a><a href="../index.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Technical Reference</a><a href="../../docs/whylisp.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Why Lisp?</a><a href="../../docs/howto.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Guides</a></div><div class="navbar__items navbar__items--right"><a href="../../docs/contribute.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Contribute!</a><a href="../../docs/help.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Getting Help</a><a href="../../docs/about.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">About</a><a href="../../blog.html" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Blog</a><a href="https://github.com/lisp-docs" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="Switch between dark and light mode (currently light mode)" aria-label="Switch between dark and light mode (currently light mode)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.
|
|||
|
<!-- -->
|
|||
|
<!-- -->
|
|||
|
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="2211-overview-of-the-lisp-printer">22.1.1 Overview of The Lisp Printer<a href="cc-b-the-lisp-printer.html#2211-overview-of-the-lisp-printer" class="hash-link" aria-label="Direct link to 22.1.1 Overview of The Lisp Printer" title="Direct link to 22.1.1 Overview of The Lisp Printer"></a></h2>
|
|||
|
<!-- -->
|
|||
|
<p>Common Lisp provides a representation of most <span><i>objects</i></span> in the form of printed text called the printed representation. Functions such as <span><b>print</b></span> take an <span><i>object</i></span> and send the characters of its printed representation to a <span><i>stream</i></span>. The collection of routines that does this is known as the (Common Lisp) printer.</p>
|
|||
|
<p>Reading a printed representation typically produces an <span><i>object</i></span> that is <span><b>equal</b></span> to the originally printed <span><i>object</i></span>.</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="22111-multiple-possible-textual-representations">22.1.1.1 Multiple Possible Textual Representations<a href="cc-b-the-lisp-printer.html#22111-multiple-possible-textual-representations" class="hash-link" aria-label="Direct link to 22.1.1.1 Multiple Possible Textual Representations" title="Direct link to 22.1.1.1 Multiple Possible Textual Representations"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>Most <span><i>objects</i></span> have more than one possible textual representation. For example, the positive <em>integer</em> with a magnitude of twenty-seven can be textually expressed in any of these ways:</p>
|
|||
|
<p>27 27. #o33 #x1B #b11011 #.(* 3 3 3) 81/3</p>
|
|||
|
<p>A list containing the two symbols A and B can also be textually expressed in a variety of ways:</p>
|
|||
|
<p>(A B) (a b) ( a b ) (\A |B|)</p>
|
|||
|
<p>(|\A|</p>
|
|||
|
<p>B</p>
|
|||
|
<p>)</p>
|
|||
|
<p>In general, from the point of view of the <em>Lisp reader</em> , wherever <span><i>whitespace</i></span> is permissible in a textual representation, any number of <span><i>spaces</i></span> and <span><i>newlines</i></span> can appear in <span><i>standard syntax</i></span> .</p>
|
|||
|
<p>When a function such as <span><b>print</b></span> produces a printed representation, it must choose from among many possible textual representations. In most cases, it chooses a program readable representation, but in certain cases it might use a more compact notation that is not program-readable.</p>
|
|||
|
<p>A number of option variables, called <span><i>printer control variables</i></span>, are provided to permit control of individual aspects of the printed representation of <span><i>objects</i></span>. Figure 22–1 shows the <em>standardized printer control variables</em>; there might also be <em>implementation-defined printer control variables</em>.</p>
|
|||
|
<p>|</p><p><strong>*print-array* *print-gensym* *print-pprint-dispatch* *print-base* *print-length* *print-pretty*</strong> </p><p><strong>*print-case* *print-level* *print-radix*</strong> </p><p><strong>*print-circle* *print-lines* *print-readably* *print-escape* *print-miser-width* *print-right-margin*</strong></p>|<p></p>
|
|||
|
<p>| :- |</p>
|
|||
|
<p><strong>Figure 22–1. Standardized Printer Control Variables</strong></p>
|
|||
|
<p>In addition to the <span><i>printer control variables</i></span>, the following additional <span><i>defined names</i></span> relate to or affect the behavior of the <em>Lisp printer</em> :</p>
|
|||
|
<p>|<strong>*package* *read-eval* readtable-case *read-default-float-format* *readtable*</strong>|</p>
|
|||
|
<p>| :- |</p>
|
|||
|
<p><strong>Figure 22–2. Additional Influences on the Lisp printer.</strong></p>
|
|||
|
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="221111-printer-escaping">22.1.1.1.1 Printer Escaping<a href="cc-b-the-lisp-printer.html#221111-printer-escaping" class="hash-link" aria-label="Direct link to 22.1.1.1.1 Printer Escaping" title="Direct link to 22.1.1.1.1 Printer Escaping"></a></h4>
|
|||
|
<!-- -->
|
|||
|
<p>The <span><i>variable</i></span> <span><b>*print-escape*</b></span> controls whether the <em>Lisp printer</em> tries to produce notations such as escape characters and package prefixes.</p>
|
|||
|
<p>The <span><i>variable</i></span> <span><b>*print-readably*</b></span> can be used to override many of the individual aspects controlled by the other <span><i>printer control variables</i></span> when program-readable output is especially important.</p>
|
|||
|
<p>One of the many effects of making the <span><i>value</i></span> of <span><b>*print-readably*</b></span> be <span><i>true</i></span> is that the <em>Lisp printer</em> behaves as if <span><b>*print-escape*</b></span> were also <span><i>true</i></span>. For notational convenience, we say that if the value of either <span><b>*print-readably*</b></span> or <span><b>*print-escape*</b></span> is <span><i>true</i></span>, then <span><i>printer escaping</i></span> is “enabled”; and we say that if the values of both <span><b>*print-readably*</b></span> and <span><b>*print-escape*</b></span> are <span><i>false</i></span>, then <span><i>printer escaping</i></span> is “disabled”.</p>
|
|||
|
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="2212-printer-dispatching">22.1.2 Printer Dispatching<a href="cc-b-the-lisp-printer.html#2212-printer-dispatching" class="hash-link" aria-label="Direct link to 22.1.2 Printer Dispatching" title="Direct link to 22.1.2 Printer Dispatching"></a></h2>
|
|||
|
<!-- -->
|
|||
|
<p>The <em>Lisp printer</em> makes its determination of how to print an <span><i>object</i></span> as follows:</p>
|
|||
|
<p>If the <span><i>value</i></span> of <span><b>*print-pretty*</b></span> is <span><i>true</i></span>, printing is controlled by the <span><i>current pprint dispatch table</i></span>; see Section 22.2.1.4 (Pretty Print Dispatch Tables).</p>
|
|||
|
<p>Otherwise (if the <span><i>value</i></span> of <span><b>*print-pretty*</b></span> is <span><i>false</i></span>), the object’s <span><b>print-object</b></span> method is used; see Section 22.1.3 (Default Print-Object Methods).</p>
|
|||
|
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="2213-default-print">22.1.3 Default Print<a href="cc-b-the-lisp-printer.html#2213-default-print" class="hash-link" aria-label="Direct link to 22.1.3 Default Print" title="Direct link to 22.1.3 Default Print"></a></h2>
|
|||
|
<!-- -->
|
|||
|
<p>This section describes the default behavior of <span><b>print-object</b></span> methods for the <em>standardized types</em>.</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="22131-printing-numbers">22.1.3.1 Printing Numbers<a href="cc-b-the-lisp-printer.html#22131-printing-numbers" class="hash-link" aria-label="Direct link to 22.1.3.1 Printing Numbers" title="Direct link to 22.1.3.1 Printing Numbers"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<!-- -->
|
|||
|
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="221311-printing-integers">22.1.3.1.1 Printing Integers<a href="cc-b-the-lisp-printer.html#221311-printing-integers" class="hash-link" aria-label="Direct link to 22.1.3.1.1 Printing Integers" title="Direct link to 22.1.3.1.1 Printing Integers"></a></h4>
|
|||
|
<!-- -->
|
|||
|
<p><em>Integers</em> are printed in the radix specified by the <span><i>current output base</i></span> in positional notation, most significant digit first. If appropriate, a radix specifier can be printed; see <span><b>*print-radix*</b></span>. If an <em>integer</em> is negative, a minus sign is printed and then the absolute value of the <em>integer</em> is printed. The <em>integer</em> zero is represented by the single digit 0 and never has a sign. A decimal point might be printed, depending on the <span><i>value</i></span> of <span><b>*print-radix*</b></span>.</p>
|
|||
|
<p>For related information about the syntax of an <em>integer</em> , see Section 2.3.2.1.1 (Syntax of an Integer).</p>
|
|||
|
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="221312-printing-ratios">22.1.3.1.2 Printing Ratios<a href="cc-b-the-lisp-printer.html#221312-printing-ratios" class="hash-link" aria-label="Direct link to 22.1.3.1.2 Printing Ratios" title="Direct link to 22.1.3.1.2 Printing Ratios"></a></h4>
|
|||
|
<!-- -->
|
|||
|
<p><span><i>Ratios</i></span> are printed as follows: the absolute value of the numerator is printed, as for an <em>integer</em> ; then a /; then the denominator. The numerator and denominator are both printed in the radix specified by the <span><i>current output base</i></span>; they are obtained as if by <span><b>numerator</b></span> and <span><b>denominator</b></span>, and so <span><i>ratios</i></span> are printed in reduced form (lowest terms). If appropriate, a radix specifier can be printed; see</p>
|
|||
|
<p><span><b>*print-radix*</b></span>. If the ratio is negative, a minus sign is printed before the numerator. For related information about the syntax of a <span><i>ratio</i></span>, see Section 2.3.2.1.2 (Syntax of a Ratio).</p>
|
|||
|
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="221313-printing-floats">22.1.3.1.3 Printing Floats<a href="cc-b-the-lisp-printer.html#221313-printing-floats" class="hash-link" aria-label="Direct link to 22.1.3.1.3 Printing Floats" title="Direct link to 22.1.3.1.3 Printing Floats"></a></h4>
|
|||
|
<!-- -->
|
|||
|
<p>If the magnitude of the <i>float</i> is either zero or between 10<sup><i>−</i>3</sup>(inclusive) and 10<sup>7</sup>(exclusive), it is printed as the integer part of the number, then a decimal point, followed by the fractional part of the number; there is always at least one digit on each side of the decimal point. If the sign of the number (as determined by <b>float-sign</b>) is negative, then a minus sign is printed before the number. If the format of the number does not match that specified by <b><em>read-default-float-format</em></b>, then the <i>exponent marker</i> for that format and the digit 0 are also printed. For example, the base of the natural logarithms as a <i>short float</i> might be printed as 2.71828S0.</p>
|
|||
|
<p>For non-zero magnitudes outside of the range 10<sup><i>−</i>3</sup>to 10<sup>7</sup>, a <i>float</i> is printed in computerized scientific notation. The representation of the number is scaled to be between 1 (inclusive) and 10 (exclusive) and then printed, with one digit before the decimal point and at least one digit after the decimal point. Next the <i>exponent marker</i> for the format is printed, except that if the format of the number matches that specified by <b><em>read-default-float-format</em></b>, then the <i>exponent marker</i> E is used. Finally, the power of ten by which the fraction must be multiplied to equal the original number is printed as a decimal integer. For example, Avogadro’s number as a <i>short float</i> is printed as 6.02S23.</p>
|
|||
|
<p>For related information about the syntax of a <span><i>float</i></span>, see Section 2.3.2.2 (Syntax of a Float).</p>
|
|||
|
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="221314-printing-complexes">22.1.3.1.4 Printing Complexes<a href="cc-b-the-lisp-printer.html#221314-printing-complexes" class="hash-link" aria-label="Direct link to 22.1.3.1.4 Printing Complexes" title="Direct link to 22.1.3.1.4 Printing Complexes"></a></h4>
|
|||
|
<!-- -->
|
|||
|
<p>A <span><i>complex</i></span> is printed as #C, an open parenthesis, the printed representation of its real part, a space, the printed representation of its imaginary part, and finally a close parenthesis.</p>
|
|||
|
<p>For related information about the syntax of a <span><i>complex</i></span> , see Section 2.3.2.3 (Syntax of a Complex) and Section 2.4.8.11 (Sharpsign C).</p>
|
|||
|
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="221315-note-about-printing-numbers">22.1.3.1.5 Note about Printing Numbers<a href="cc-b-the-lisp-printer.html#221315-note-about-printing-numbers" class="hash-link" aria-label="Direct link to 22.1.3.1.5 Note about Printing Numbers" title="Direct link to 22.1.3.1.5 Note about Printing Numbers"></a></h4>
|
|||
|
<!-- -->
|
|||
|
<p>The printed representation of a number must not contain <em>escape characters</em>; see Section 2.3.1.1.1 (Escape Characters and Potential Numbers).</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="22132-printing-characters">22.1.3.2 Printing Characters<a href="cc-b-the-lisp-printer.html#22132-printing-characters" class="hash-link" aria-label="Direct link to 22.1.3.2 Printing Characters" title="Direct link to 22.1.3.2 Printing Characters"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>When <span><i>printer escaping</i></span> is disabled, a <span><i>character</i></span> prints as itself; it is sent directly to the output <span><i>stream</i></span>. When <span><i>printer escaping</i></span> is enabled, then #\ syntax is used.</p>
|
|||
|
<p>When the printer types out the name of a <span><i>character</i></span> , it uses the same table as the #\ <span><i>reader macro</i></span> would use; therefore any <span><i>character</i></span> name that is typed out is acceptable as input (in that <span><i>implementation</i></span>). If a <em>non-graphic character</em> has a <em>standardized name</em><sub>5</sub>, that <span><i>name</i></span> is preferred over non-standard <span><i>names</i></span> for printing in #\ notation. For the <em>graphic standard characters</em>, the <span><i>character</i></span> itself is always used for printing in #\ notation—even if the <span><i>character</i></span> also has a <span><i>name</i></span><sub>5</sub>.</p>
|
|||
|
<p>For details about the #\ <span><i>reader macro</i></span>, see Section 2.4.8.1 (Sharpsign Backslash).</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="22133-printing-symbols">22.1.3.3 Printing Symbols<a href="cc-b-the-lisp-printer.html#22133-printing-symbols" class="hash-link" aria-label="Direct link to 22.1.3.3 Printing Symbols" title="Direct link to 22.1.3.3 Printing Symbols"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>When <span><i>printer escaping</i></span> is disabled, only the characters of the <span><i>symbol</i></span>’s <span><i>name</i></span> are output (but the case in which to print characters in the <span><i>name</i></span> is controlled by <span><b>*print-case*</b></span>; see Section 22.1.3.3.2 (Effect of Readtable Case on the Lisp Printer)).</p>
|
|||
|
<p>The remainder of this section applies only when <span><i>printer escaping</i></span> is enabled.</p>
|
|||
|
<p>When printing a <span><i>symbol</i></span>, the printer inserts enough <span><i>single escape</i></span> and/or <span><i>multiple escape</i></span> characters (<em>backslashes</em> and/or <span><i>vertical-bars</i></span>) so that if <span><b>read</b></span> were called with the same <span><b>*readtable*</b></span> and with <strong>*read-base*</strong> bound to the <span><i>current output base</i></span>, it would return the same <span><i>symbol</i></span> (if it is not <span><i>apparently uninterned</i></span>) or an <em>uninterned symbol</em> with the same <span><i>print name</i></span> (otherwise).</p>
|
|||
|
<p>For example, if the <span><i>value</i></span> of <strong>*print-base*</strong> were 16 when printing the symbol face, it would have to be printed as \FACE or \Face or |FACE|, because the token face would be read as a hexadecimal number (decimal value 64206) if the <span><i>value</i></span> of <strong>*read-base*</strong> were 16.</p>
|
|||
|
<p>For additional restrictions concerning characters with nonstandard <span><i>syntax types</i></span> in the <span><i>current readtable</i></span>, see the <span><i>variable</i></span> <span><b>*print-readably*</b></span></p>
|
|||
|
<p>For information about how the <em>Lisp reader</em> parses <span><i>symbols</i></span>, see Section 2.3.4 (Symbols as Tokens) and Section 2.4.8.5 (Sharpsign Colon).</p>
|
|||
|
<p><span><b>nil</b></span> might be printed as () when <span><b>*print-pretty*</b></span> is <span><i>true</i></span> and <span><i>printer escaping</i></span> is enabled.</p>
|
|||
|
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="221331-package-prefixes-for-symbols">22.1.3.3.1 Package Prefixes for Symbols<a href="cc-b-the-lisp-printer.html#221331-package-prefixes-for-symbols" class="hash-link" aria-label="Direct link to 22.1.3.3.1 Package Prefixes for Symbols" title="Direct link to 22.1.3.3.1 Package Prefixes for Symbols"></a></h4>
|
|||
|
<!-- -->
|
|||
|
<p><em>Package prefixes</em> are printed if necessary. The rules for <em>package prefixes</em> are as follows. When the <span><i>symbol</i></span> is printed, if it is in the KEYWORD <span><i>package</i></span>, then it is printed with a preceding <span><i>colon</i></span>; otherwise, if it is <span><i>accessible</i></span> in the <span><i>current package</i></span>, it is printed without any <span><i>package prefix</i></span> ; otherwise, it is printed with a <span><i>package prefix</i></span> .</p>
|
|||
|
<p>A <span><i>symbol</i></span> that is <span><i>apparently uninterned</i></span> is printed preceded by “#:” if <span><b>*print-gensym*</b></span> is <span><i>true</i></span> and <span><i>printer escaping</i></span> is enabled; if <span><b>*print-gensym*</b></span> is <span><i>false</i></span> or <span><i>printer escaping</i></span> is disabled, then the <span><i>symbol</i></span> is printed without a prefix, as if it were in the <span><i>current package</i></span>.</p>
|
|||
|
<p>Because the #: syntax does not intern the following symbol, it is necessary to use circular-list syntax if <span><b>*print-circle*</b></span> is <span><i>true</i></span> and the same uninterned symbol appears several times in an expression to be printed. For example, the result of</p>
|
|||
|
<p>(let ((x (make-symbol "FOO"))) (list x x))</p>
|
|||
|
<p>would be printed as (#<!-- -->:foo<!-- --> #<!-- -->:foo<!-- -->) if <span><b>*print-circle*</b></span> were <span><i>false</i></span>, but as (#1=#<!-- -->:foo<!-- --> #1#) if <span><b>*print-circle*</b></span> were <span><i>true</i></span>.</p>
|
|||
|
<p>A summary of the preceding package prefix rules follows:</p>
|
|||
|
<p>foo<!-- -->:bar</p>
|
|||
|
<p>foo<!-- -->:bar<!-- --> is printed when <span><i>symbol</i></span> bar is external in its <span><i>home package</i></span> foo and is not <span><i>accessible</i></span> in the <span><i>current package</i></span>.</p>
|
|||
|
<p>foo::bar</p>
|
|||
|
<p>foo::bar is printed when bar is internal in its <span><i>home package</i></span> foo and is not <span><i>accessible</i></span> in the <span><i>current package</i></span>.</p>
|
|||
|
<p>:bar</p>
|
|||
|
<p>:bar<!-- --> is printed when the home package of bar is the KEYWORD <span><i>package</i></span>.</p>
|
|||
|
<p>#<!-- -->:bar</p>
|
|||
|
<p>#<!-- -->:bar<!-- --> is printed when bar is <em>apparently uninterned</em>, even in the pathological case that bar has no <em>home package</em> but is nevertheless somehow <em>accessible</em> in the <em>current package</em>.</p>
|
|||
|
<h4 class="anchor anchorWithStickyNavbar_LWe7" id="221332-effect-of-readtable-case-on-the-lisp-printer">22.1.3.3.2 Effect of Readtable Case on the Lisp Printer<a href="cc-b-the-lisp-printer.html#221332-effect-of-readtable-case-on-the-lisp-printer" class="hash-link" aria-label="Direct link to 22.1.3.3.2 Effect of Readtable Case on the Lisp Printer" title="Direct link to 22.1.3.3.2 Effect of Readtable Case on the Lisp Printer"></a></h4>
|
|||
|
<!-- -->
|
|||
|
<p>When <span><i>printer escaping</i></span> is disabled, or the characters under consideration are not already quoted specifically by <span><i>single escape</i></span> or <span><i>multiple escape</i></span> syntax, the <span><i>readtable case</i></span> of the <span><i>current readtable</i></span> affects the way the <em>Lisp printer</em> writes <span><i>symbols</i></span> in the following ways:</p>
|
|||
|
<p>:upcase</p>
|
|||
|
<p>When the <span><i>readtable case</i></span> is <!-- -->:upcase<!-- -->, <em>uppercase characters</em> are printed in the case specified by <span><b>*print-case*</b></span>, and <em>lowercase characters</em> are printed in their own case.</p>
|
|||
|
<p>:downcase</p>
|
|||
|
<p>When the <span><i>readtable case</i></span> is <!-- -->:downcase<!-- -->, <em>uppercase characters</em> are printed in their own case, and <em>lowercase characters</em> are printed in the case specified by <span><b>*print-case*</b></span>.</p>
|
|||
|
<p>:preserve</p>
|
|||
|
<p>When the <span><i>readtable case</i></span> is <!-- -->:preserve<!-- -->, all <em>alphabetic characters</em> are printed in their own case.</p>
|
|||
|
<p>:invert</p>
|
|||
|
<p>When the <span><i>readtable case</i></span> is <!-- -->:invert<!-- -->, the case of all <em>alphabetic characters</em> in single case symbol names is inverted. Mixed-case symbol names are printed as is.</p>
|
|||
|
<p>The rules for escaping <em>alphabetic characters</em> in symbol names are affected by the <span><b>readtable-case</b></span> if <span><i>printer escaping</i></span> is enabled. <em>Alphabetic characters</em> are escaped as follows:</p>
|
|||
|
<p>:upcase</p>
|
|||
|
<p>When the <span><i>readtable case</i></span> is <!-- -->:upcase<!-- -->, all <em>lowercase characters</em> must be escaped.</p>
|
|||
|
<p>:downcase</p>
|
|||
|
<p>When the <span><i>readtable case</i></span> is <!-- -->:downcase<!-- -->, all <em>uppercase characters</em> must be escaped.</p>
|
|||
|
<p>:preserve</p>
|
|||
|
<p>When the <span><i>readtable case</i></span> is <!-- -->:preserve<!-- -->, no <em>alphabetic characters</em> need be escaped.</p>
|
|||
|
<p>:invert</p>
|
|||
|
<p>When the <span><i>readtable case</i></span> is <!-- -->:invert<!-- -->, no <em>alphabetic characters</em> need be escaped.</p>
|
|||
|
<h5 class="anchor anchorWithStickyNavbar_LWe7" id="2213321-examples-of-effect-of-readtable-case-on-the-lisp-printer">22.1.3.3.2.1 Examples of Effect of Readtable Case on the Lisp Printer<a href="cc-b-the-lisp-printer.html#2213321-examples-of-effect-of-readtable-case-on-the-lisp-printer" class="hash-link" aria-label="Direct link to 22.1.3.3.2.1 Examples of Effect of Readtable Case on the Lisp Printer" title="Direct link to 22.1.3.3.2.1 Examples of Effect of Readtable Case on the Lisp Printer"></a></h5>
|
|||
|
<!-- -->
|
|||
|
<div class="language-lisp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-lisp codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">(</span><span class="token defun keyword" style="color:#00009f">defun</span><span class="token defun"> </span><span class="token defun function" style="color:#d73a49">test-readtable-case-printing</span><span class="token defun"> </span><span class="token defun punctuation" style="color:#393A34">(</span><span class="token defun arguments"></span><span class="token defun punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">let</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">\*readtable\* </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">copy-readtable</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">nil</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">\*print-case\* \*print-case\*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">format</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">t</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"</span><span class="token string argument" style="color:#e3116c">READTABLE-CASE</span><span class="token string" style="color:#e3116c"> \*PRINT-CASE\* Symbol-name Output~ </span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">~%–––––––––––––––––––––––––~ </span><br></span><span class="token-line" style="color:#393A34"><span class="token string" style="color:#e3116c">~%"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">dolist</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">readtable-case</span><span class="token plain"> ’</span><span class="token punctuation" style="color:#393A34">(</span><span class="token lisp-property property" style="color:#36acaa">:upcase</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:downcase</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:preserve</span><span class="token plain"> </span><span class="token lisp-property property" style="color:#36acaa">:invert</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="22134-printing-strings">22.1.3.4 Printing Strings<a href="cc-b-the-lisp-printer.html#22134-printing-strings" class="hash-link" aria-label="Direct link to 22.1.3.4 Printing Strings" title="Direct link to 22.1.3.4 Printing Strings"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>The characters of the <span><i>string</i></span> are output in order. If <span><i>printer escaping</i></span> is enabled, a <span><i>double-quote</i></span> is output before and after, and all <span><i>double-quotes</i></span> and <span><i>single escapes</i></span> are preceded by <span><i>backslash</i></span>. The printing of <span><i>strings</i></span> is not affected by <span><b>*print-array*</b></span>. Only the <em>active elements</em> of the <span><i>string</i></span> are printed.</p>
|
|||
|
<p>For information on how the <em>Lisp reader</em> parses <span><i>strings</i></span>, see Section 2.4.5 (Double-Quote).</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="22135-printing-lists-and-conses">22.1.3.5 Printing Lists and Conses<a href="cc-b-the-lisp-printer.html#22135-printing-lists-and-conses" class="hash-link" aria-label="Direct link to 22.1.3.5 Printing Lists and Conses" title="Direct link to 22.1.3.5 Printing Lists and Conses"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>Wherever possible, list notation is preferred over dot notation. Therefore the following algorithm is used to print a <em>cons x</em>:</p>
|
|||
|
<p>1. A <span><i>left-parenthesis</i></span> is printed.</p>
|
|||
|
<p>2. The <span><i>car</i></span> of <em>x</em> is printed.</p>
|
|||
|
<p>3. If the <span><i>cdr</i></span> of <em>x</em> is itself a <span><i>cons</i></span>, it is made to be the current <span><i>cons</i></span> (<em>i.e.</em>, <em>x</em> becomes that <span><i>cons</i></span>), a <span><i>space</i></span> is printed, and step 2 is re-entered.</p>
|
|||
|
<p>4. If the <span><i>cdr</i></span> of <em>x</em> is not <span><i>null</i></span>, a <span><i>space</i></span>, a <span><i>dot</i></span>, a <span><i>space</i></span>, and the <span><i>cdr</i></span> of <em>x</em> are printed.</p>
|
|||
|
<p>5. A <span><i>right-parenthesis</i></span> is printed.</p>
|
|||
|
<p>Actually, the above algorithm is only used when <span><b>*print-pretty*</b></span> is <span><i>false</i></span>. When <span><b>*print-pretty*</b></span> is <span><i>true</i></span> (or when <span><b>pprint</b></span> is used), additional <span><i>whitespace</i></span><sub>1</sub> may replace the use of a single <span><i>space</i></span>, and a more elaborate algorithm with similar goals but more presentational flexibility is used; see Section 22.1.2 (Printer Dispatching).</p>
|
|||
|
<p>Although the two expressions below are equivalent, and the reader accepts either one and produces the same <span><i>cons</i></span>, the printer always prints such a <span><i>cons</i></span> in the second form.</p>
|
|||
|
<p>(a . (b . ((c . (d . nil)) . (e . nil))))</p>
|
|||
|
<p>(a b (c d) e)</p>
|
|||
|
<p>The printing of <em>conses</em> is affected by <strong>*print-level*</strong>, <span><b>*print-length*</b></span>, and <span><b>*print-circle*</b></span>. Following are examples of printed representations of <span><i>lists</i></span>:</p>
|
|||
|
<p>(a . b) ;A dotted pair of a and b</p>
|
|||
|
<p>(a.b) ;A list of one element, the symbol named a.b</p>
|
|||
|
<p>(a. b) ;A list of two elements a. and b</p>
|
|||
|
<p>(a .b) ;A list of two elements a and .b</p>
|
|||
|
<p>(a b . c) ;A dotted list of a and b with c at the end; two conses</p>
|
|||
|
<p>.iot ;The symbol whose name is .iot</p>
|
|||
|
<p>(. b) ;Invalid – an error is signaled if an attempt is made to read</p>
|
|||
|
<p>;this syntax.</p>
|
|||
|
<p>(a .) ;Invalid – an error is signaled.</p>
|
|||
|
<p>(a .. b) ;Invalid – an error is signaled.</p>
|
|||
|
<p>(a . . b) ;Invalid – an error is signaled.</p>
|
|||
|
<p>(a b c ...) ;Invalid – an error is signaled.</p>
|
|||
|
<p>(a . b) ;A list of three elements a, ., and b</p>
|
|||
|
<p>(a |.| b) ;A list of three elements a, ., and b</p>
|
|||
|
<p>(a ... b) ;A list of three elements a, ..., and b</p>
|
|||
|
<p>(a |...| b) ;A list of three elements a, ..., and b</p>
|
|||
|
<p>For information on how the <em>Lisp reader</em> parses <span><i>lists</i></span> and <em>conses</em>, see Section 2.4.1 (Left-Parenthesis).</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="22136-printing-bit-vectors">22.1.3.6 Printing Bit Vectors<a href="cc-b-the-lisp-printer.html#22136-printing-bit-vectors" class="hash-link" aria-label="Direct link to 22.1.3.6 Printing Bit Vectors" title="Direct link to 22.1.3.6 Printing Bit Vectors"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>A <span><i>bit vector</i></span> is printed as #* followed by the bits of the <span><i>bit vector</i></span> in order. If <span><b>*print-array*</b></span> is <span><i>false</i></span>, then the <span><i>bit vector</i></span> is printed in a format (using #<) that is concise but not readable. Only the <em>active elements</em> of the <span><i>bit vector</i></span> are printed.</p>
|
|||
|
<p>For information on <em>Lisp reader</em> parsing of <span><i>bit vectors</i></span>, see Section 2.4.8.4 (Sharpsign Asterisk).</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="22137-printing-other-vectors">22.1.3.7 Printing Other Vectors<a href="cc-b-the-lisp-printer.html#22137-printing-other-vectors" class="hash-link" aria-label="Direct link to 22.1.3.7 Printing Other Vectors" title="Direct link to 22.1.3.7 Printing Other Vectors"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>If <span><b>*print-array*</b></span> is <span><i>true</i></span> and <span><b>*print-readably*</b></span> is <span><i>false</i></span>, any <span><i>vector</i></span> other than a <span><i>string</i></span> or <span><i>bit vector</i></span> is printed using general-vector syntax; this means that information about specialized vector representations does not appear. The printed representation of a zero-length <span><i>vector</i></span> is #(). The printed representation of a non-zero-length <span><i>vector</i></span> begins with #(. Following that, the first element of the <span><i>vector</i></span> is printed. If there are any other elements, they are printed in turn, with each such additional element preceded by a <span><i>space</i></span> if <span><b>*print-pretty*</b></span> is <span><i>false</i></span>, or <span><i>whitespace</i></span><sub>1</sub> if <span><b>*print-pretty*</b></span> is <span><i>true</i></span>. A <span><i>right-parenthesis</i></span> after the last element terminates the printed representation of the <span><i>vector</i></span> . The printing of <span><i>vectors</i></span> is affected by <strong>*print-level*</strong> and <span><b>*print-length*</b></span>. If the <span><i>vector</i></span> has a <span><i>fill pointer</i></span> , then only those elements below the <span><i>fill pointer</i></span> are printed.</p>
|
|||
|
<p>If both <span><b>*print-array*</b></span> and <span><b>*print-readably*</b></span> are <span><i>false</i></span>, the <span><i>vector</i></span> is not printed as described above, but in a format (using #<) that is concise but not readable.</p>
|
|||
|
<p>If <span><b>*print-readably*</b></span> is <span><i>true</i></span>, the <span><i>vector</i></span> prints in an <span><i>implementation-defined</i></span> manner; see the <span><i>variable</i></span> <span><b>*print-readably*</b></span>.</p>
|
|||
|
<p>For information on how the <em>Lisp reader</em> parses these “other <span><i>vectors</i></span>,” see Section 2.4.8.3 (Sharpsign Left-Parenthesis).</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="22138-printing-other-arrays">22.1.3.8 Printing Other Arrays<a href="cc-b-the-lisp-printer.html#22138-printing-other-arrays" class="hash-link" aria-label="Direct link to 22.1.3.8 Printing Other Arrays" title="Direct link to 22.1.3.8 Printing Other Arrays"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>If <span><b>*print-array*</b></span> is <span><i>true</i></span> and <span><b>*print-readably*</b></span> is <span><i>false</i></span>, any <span><i>array</i></span> other than a <span><i>vector</i></span> is printed using #nA format. Let n be the <span><i>rank</i></span> of the <span><i>array</i></span>. Then # is printed, then n as a decimal integer, then A, then n open parentheses. Next the <span><i>elements</i></span> are scanned in row-major order, using <span><b>write</b></span> on each <span><i>element</i></span>, and separating <span><i>elements</i></span> from each other with <span><i>whitespace</i></span><sub>1</sub>. The array’s dimensions are numbered 0 to n-1 from left to right, and are enumerated with the rightmost index changing fastest. Every time the index for dimension j is incremented, the following actions are taken:</p>
|
|||
|
<p><em>•</em> If j < n-1, then a close parenthesis is printed.</p>
|
|||
|
<p><em>•</em> If incrementing the index for dimension j caused it to equal dimension j, that index is reset to zero and the index for dimension j-1 is incremented (thereby performing these three steps recursively), unless j=0, in which case the entire algorithm is terminated. If incrementing the index for dimension j did not cause it to equal dimension j, then a space is printed.</p>
|
|||
|
<p><em>•</em> If j < n-1, then an open parenthesis is printed.</p>
|
|||
|
<p>This causes the contents to be printed in a format suitable for <!-- -->:initial-contents<!-- --> to <span><b>make-array</b></span>. The lists effectively printed by this procedure are subject to truncation by <strong>*print-level*</strong> and <span><b>*print-length*</b></span>.</p>
|
|||
|
<p>If the <span><i>array</i></span> is of a specialized <span><i>type</i></span>, containing bits or characters, then the innermost lists generated by the algorithm given above can instead be printed using bit-vector or string syntax, provided that these innermost lists would not be subject to truncation by <span><b>*print-length*</b></span>.</p>
|
|||
|
<p>If both <span><b>*print-array*</b></span> and <span><b>*print-readably*</b></span> are <span><i>false</i></span>, then the <span><i>array</i></span> is printed in a format (using #<) that is concise but not readable.</p>
|
|||
|
<p>If <span><b>*print-readably*</b></span> is <span><i>true</i></span>, the <span><i>array</i></span> prints in an <span><i>implementation-defined</i></span> manner; see the <span><i>variable</i></span> <span><b>*print-readably*</b></span>. In particular, this may be important for arrays having some dimension 0.</p>
|
|||
|
<p>For information on how the <em>Lisp reader</em> parses these “other <span><i>arrays</i></span>,” see Section 2.4.8.12 (Sharpsign A).</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="22139-examples-of-printing-arrays">22.1.3.9 Examples of Printing Arrays<a href="cc-b-the-lisp-printer.html#22139-examples-of-printing-arrays" class="hash-link" aria-label="Direct link to 22.1.3.9 Examples of Printing Arrays" title="Direct link to 22.1.3.9 Examples of Printing Arrays"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<div class="language-lisp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-lisp codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">let</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">a</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">make-array</span><span class="token plain"> ’</span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">3</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">3</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">\*print-pretty\* </span><span class="token boolean" style="color:#36acaa">t</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">\*print-array\* </span><span class="token boolean" style="color:#36acaa">t</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">dotimes</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">i</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">3</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">dotimes</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">j</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">3</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">setf</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">aref</span><span class="token plain"> a i j</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">format</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">nil</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"<~</span><span class="token string argument" style="color:#e3116c">D</span><span class="token string" style="color:#e3116c">,~D>"</span><span class="token plain"> i j</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="toke
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="221310-printing-random-states">22.1.3.10 Printing Random States<a href="cc-b-the-lisp-printer.html#221310-printing-random-states" class="hash-link" aria-label="Direct link to 22.1.3.10 Printing Random States" title="Direct link to 22.1.3.10 Printing Random States"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>A specific syntax for printing <span><i>objects</i></span> of <span><i>type</i></span> <span><b>random-state</b></span> is not specified. However, every <span><i>implementation</i></span> must arrange to print a <em>random state object</em> in such a way that, within the same implementation, <span><b>read</b></span> can construct from the printed representation a copy of the <span><i>random state</i></span> object as if the copy had been made by <span><b>make-random-state</b></span>.</p>
|
|||
|
<p>If the type <span><i>random state</i></span> is effectively implemented by using the machinery for <span><b>defstruct</b></span>, the usual structure syntax can then be used for printing <span><i>random state</i></span> objects; one might look something like</p>
|
|||
|
<p>#S(RANDOM-STATE <!-- -->:DATA<!-- --> #(14 49 98436589 786345 8734658324 ... ))</p>
|
|||
|
<p>where the components are <span><i>implementation-dependent</i></span>.</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="221311-printing-pathnames">22.1.3.11 Printing Pathnames<a href="cc-b-the-lisp-printer.html#221311-printing-pathnames" class="hash-link" aria-label="Direct link to 22.1.3.11 Printing Pathnames" title="Direct link to 22.1.3.11 Printing Pathnames"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>When <span><i>printer escaping</i></span> is enabled, the syntax #P"..." is how a <span><i>pathname</i></span> is printed by <span><b>write</b></span> and the other functions herein described. The "..." is the namestring representation of the pathname.</p>
|
|||
|
<p>When <span><i>printer escaping</i></span> is disabled, <span><b>write</b></span> writes a <em>pathname P</em> by writing (namestring <em>P</em>) instead. For information on how the <em>Lisp reader</em> parses <span><i>pathnames</i></span>, see Section 2.4.8.14 (Sharpsign P).</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="221312-printing-structures">22.1.3.12 Printing Structures<a href="cc-b-the-lisp-printer.html#221312-printing-structures" class="hash-link" aria-label="Direct link to 22.1.3.12 Printing Structures" title="Direct link to 22.1.3.12 Printing Structures"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>By default, a <span><i>structure</i></span> of type <em>S</em> is printed using #S syntax. This behavior can be customized by specifying a <!-- -->:print-function<!-- --> or <!-- -->:print-object<!-- --> option to the <span><b>defstruct</b></span> <span><i>form</i></span> that defines <em>S</em>, or by writing a <span><b>print-object</b></span> <span><i>method</i></span> that is <span><i>specialized</i></span> for <span><i>objects</i></span> of type <em>S</em>.</p>
|
|||
|
<p>Different structures might print out in different ways; the default notation for structures is: #S(<em>structure-name {slot-key slot-value}</em>*)</p>
|
|||
|
<p>where #S indicates structure syntax, <em>structure-name</em> is a <span><i>structure name</i></span>, each <em>slot-key</em> is an initialization argument <span><i>name</i></span> for a <span><i>slot</i></span> in the <span><i>structure</i></span>, and each corresponding <em>slot-value</em> is a representation of the <span><i>object</i></span> in that <span><i>slot</i></span>.</p>
|
|||
|
<p>For information on how the <em>Lisp reader</em> parses <span><i>structures</i></span>, see Section 2.4.8.13 (Sharpsign S).</p>
|
|||
|
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="221313-printing-other-objects">22.1.3.13 Printing Other Objects<a href="cc-b-the-lisp-printer.html#221313-printing-other-objects" class="hash-link" aria-label="Direct link to 22.1.3.13 Printing Other Objects" title="Direct link to 22.1.3.13 Printing Other Objects"></a></h3>
|
|||
|
<!-- -->
|
|||
|
<p>Other <span><i>objects</i></span> are printed in an <span><i>implementation-dependent</i></span> manner. It is not required that an <span><i>implementation</i></span> print those <em>objects readably</em>.</p>
|
|||
|
<p>For example, <span><i>hash tables</i></span>, <span><i>readtables</i></span>, <span><i>packages</i></span>, <span><i>streams</i></span>, and <span><i>functions</i></span> might not print <span><i>readably</i></span>.</p>
|
|||
|
<p>A common notation to use in this circumstance is #<...>. Since #< is not readable by the <em>Lisp reader</em> , the precise format of the text which follows is not important, but a common format to use is that provided by the <span><b>print-unreadable-object</b></span> <span><i>macro</i></span>.</p>
|
|||
|
<p>For information on how the <em>Lisp reader</em> treats this notation, see Section 2.4.8.20 (Sharpsign Less-Than-Sign). For information on how to notate <span><i>objects</i></span> that cannot be printed <span><i>readably</i></span>, see Section 2.4.8.6 (Sharpsign Dot).</p>
|
|||
|
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="2214-examples-of-printer-behavior">22.1.4 Examples of Printer Behavior<a href="cc-b-the-lisp-printer.html#2214-examples-of-printer-behavior" class="hash-link" aria-label="Direct link to 22.1.4 Examples of Printer Behavior" title="Direct link to 22.1.4 Examples of Printer Behavior"></a></h2>
|
|||
|
<!-- -->
|
|||
|
<!-- -->
|
|||
|
<div class="language-lisp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-lisp codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">let</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">\*print-escape\* </span><span class="token boolean" style="color:#36acaa">t</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">fresh-line</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">write</span><span class="token plain"> #\a</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">▷ #\a </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">→ #\a </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">let</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">\*print-escape\* </span><span class="token boolean" style="color:#36acaa">nil</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">\*print-readably\* </span><span class="token boolean" style="color:#36acaa">nil</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">fresh-line</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">write</span><span class="token plain"> #\a</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">▷ a </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">→ #\a </span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">progn</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">fresh-line</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token car">prin1</span><span class="token plain"> #\a</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token p
|
|||
|
</body>
|
|||
|
</html>
|