1
0
Fork 0
cl-sites/novaspec.org/cl/v_print-readably.html

464 lines
10 KiB
HTML
Raw Normal View History

2025-02-05 18:52:26 +01:00
<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>*print-readably* | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="v_print-readably.html"
><LINK REL="next" HREF="v_print-right-margin.html" TYPE="text/html" TITLE="*print-right-margin*"
><LINK REL="prev" HREF="v_print-pretty.html" TYPE="text/html" TITLE="*print-pretty*"
><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"
>&#8594; <A HREF="22_Printer.html"
>22. Printer</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="22_4_Printer_Dictionary.html"
>22.4 Printer Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="v_print-readably.html"
>*print-readably*</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="v_print-pretty.html" CLASS="prev"
>&#8592;</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="v_print-right-margin.html" CLASS="next"
>&#8594;</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="*print-readably*"
></SPAN
><SPAN CLASS="cmsy"
>*</SPAN
><B
>print-readably</B
><SPAN CLASS="cmsy"
>*</SPAN
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Variable</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Value Type</B
></DT
><DD
><P CLASS="j"
>a <A HREF="26_1_Glossary.html#generalized_boolean"
><EM CLASS="term"
>generalized boolean</EM
></A
>.</P
></DD
><DT
><B
>Initial Value</B
></DT
><DD
><P CLASS="j"
><A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
>If <A HREF="v_print-readably.html" CLASS="varref"
><B
>*print-readably*</B
></A
> is <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>, some special rules for printing <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>objects</EM
></A
> go into effect. Specifically, printing any <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> <I
>O</I
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>1</SPAN
></SUB
> produces a printed representation that, when seen by the <A HREF="26_1_Glossary.html#Lisp_reader"
><EM CLASS="term"
>Lisp reader</EM
></A
> while the <A HREF="26_1_Glossary.html#standard_readtable"
><EM CLASS="term"
>standard readtable</EM
></A
> is in effect, will produce an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> <I
>O</I
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>2</SPAN
></SUB
> that is <A HREF="26_1_Glossary.html#similar"
><EM CLASS="term"
>similar</EM
></A
> to <I
>O</I
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>1</SPAN
></SUB
>. The printed representation produced might or might not be the same as the printed representation produced when <A HREF="v_print-readably.html" CLASS="varref"
><B
>*print-readably*</B
></A
> is <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
>. If printing an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> <A HREF="26_1_Glossary.html#readably"
><EM CLASS="term"
>readably</EM
></A
> is not possible, an error of <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> <A HREF="t_print-not-readable.html" CLASS="typeref"
><B
>print-not-readable</B
></A
> is signaled rather than using a syntax (<I CLASS="i"
><I
>e.g.</I
></I
>, the &#8220;<CODE CLASS="f"
>#&lt;</CODE
>&#8221; syntax) that would not be readable by the same <A HREF="26_1_Glossary.html#implementation"
><EM CLASS="term"
>implementation</EM
></A
>. If the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
> of some other <A HREF="26_1_Glossary.html#printer_control_variable"
><EM CLASS="term"
>printer control variable</EM
></A
> is such that these requirements would be violated, the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
> of that other <A HREF="26_1_Glossary.html#variable"
><EM CLASS="term"
>variable</EM
></A
> is ignored. </P
><P CLASS="j"
>Specifically, if <A HREF="v_print-readably.html" CLASS="varref"
><B
>*print-readably*</B
></A
> is <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>, printing proceeds as if <A HREF="v_print-escape.html" CLASS="varref"
><B
>*print-escape*</B
></A
>, <A HREF="v_print-array.html" CLASS="varref"
><B
>*print-array*</B
></A
>, and <A HREF="v_print-gensym.html" CLASS="varref"
><B
>*print-gensym*</B
></A
> were also <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>, and as if <A HREF="v_print-level.html" CLASS="varref"
><B
>*print-length*</B
></A
>, <A HREF="v_print-level.html" CLASS="varref"
><B
>*print-level*</B
></A
>, and <A HREF="v_print-lines.html" CLASS="varref"
><B
>*print-lines*</B
></A
> were <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
>. </P
><P CLASS="j"
>If <A HREF="v_print-readably.html" CLASS="varref"
><B
>*print-readably*</B
></A
> is <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
>, the normal rules for printing and the normal interpretations of other <A HREF="26_1_Glossary.html#printer_control_variable"
><EM CLASS="term"
>printer control variables</EM
></A
> are in effect. </P
><P CLASS="j"
>Individual <A HREF="26_1_Glossary.html#method"
><EM CLASS="term"
>methods</EM
></A
> for <A HREF="f_print-object.html" CLASS="funref"
><B
>print-object</B
></A
>, including user-defined <A HREF="26_1_Glossary.html#method"
><EM CLASS="term"
>methods</EM
></A
>, are responsible for implementing these requirements. </P
><P CLASS="j"
>If <A HREF="v_read-eval.html" CLASS="varref"
><B
>*read-eval*</B
></A
> is <A HREF="26_1_Glossary.html#false"
><EM CLASS="term"
>false</EM
></A
> and <A HREF="v_print-readably.html" CLASS="varref"
><B
>*print-readably*</B
></A
> is <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
>, any such method that would output a reference to the &#8220;<CODE CLASS="f"
>#.</CODE
>&#8221; <A HREF="26_1_Glossary.html#reader_macro"
><EM CLASS="term"
>reader macro</EM
></A
> will either output something else or will signal an error (as described above).</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (let ((x (list "a" '\a (gensym) '((a (b (c))) d e f g)))
(*print-escape* nil)
(*print-gensym* nil)
(*print-level* 3)
(*print-length* 3))
(write x)
(let ((*print-readably* t))
(terpri)
(write x)
:done))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (a a G4581 ((A #) D E ...))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> ("a" |a| #:G4581 ((A (B (C))) D E F G))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> :DONE
;; This is setup code is shared between the examples
;; of three hypothetical implementations which follow.
(setq table (make-hash-table)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;HASH-TABLE EQL 0/120 32005763&gt;
(setf (gethash table 1) 'one) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> ONE
(setf (gethash table 2) 'two) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> TWO
;; Implementation A
(let ((*print-readably* t)) (print table))
Error: Can't print #&lt;HASH-TABLE EQL 0/120 32005763&gt; readably.
;; Implementation B
;; No standardized #S notation for hash tables is defined,
;; but there might be an implementation-defined notation.
(let ((*print-readably* t)) (print table))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> #S(HASH-TABLE :TEST EQL :SIZE 120 :CONTENTS (1 ONE 2 TWO))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;HASH-TABLE EQL 0/120 32005763&gt;
;; Implementation C
;; Note that #. notation can only be used if *READ-EVAL* is true.
;; If *READ-EVAL* were false, this same implementation might have to
;; signal an error unless it had yet another printing strategy to fall
;; back on.
(let ((*print-readably* t)) (print table))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> #.(LET ((HASH-TABLE (MAKE-HASH-TABLE)))
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (SETF (GETHASH 1 HASH-TABLE) ONE)
<SPAN CLASS="cmr"
>&#8883;</SPAN
> (SETF (GETHASH 2 HASH-TABLE) TWO)
<SPAN CLASS="cmr"
>&#8883;</SPAN
> HASH-TABLE)
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;HASH-TABLE EQL 0/120 32005763&gt;</PRE
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_write.html" CLASS="funref"
><B
>write</B
></A
>, <A HREF="f_print-unreadable-object.html" CLASS="macref"
><B
>print-unreadable-object</B
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
>The rules for &#8220;<A HREF="26_1_Glossary.html#similarity"
><EM CLASS="term"
>similarity</EM
></A
>&#8221; imply that <CODE CLASS="f"
>#A</CODE
> or <CODE CLASS="f"
>#(</CODE
> syntax cannot be used for <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>arrays</EM
></A
> of <A HREF="26_1_Glossary.html#element_type"
><EM CLASS="term"
>element type</EM
></A
> other than <A HREF="t_t.html" CLASS="typeref"
><B
>t</B
></A
>. An implementation will have to use another syntax or signal an error of <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>type</EM
></A
> <A HREF="t_print-not-readable.html" CLASS="typeref"
><B
>print-not-readable</B
></A
>.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="v_print-pretty.html" CLASS="prev"
>&#8592;</A
><A HREF="v_print-right-margin.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>