1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/f_pr_obj.htm
2024-04-01 10:24:07 +02:00

81 lines
14 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Standard Generic Function PRINT-OBJECT</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="f_ppr_ta.htm">
<LINK REL=UP HREF="c_printe.htm">
<LINK REL=NEXT HREF="m_pr_unr.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="f_ppr_ta.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_printe.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="m_pr_unr.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="print-object"><I>Standard Generic Function</I> <B>PRINT-OBJECT</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>print-object</B> <I>object stream</I> =&gt; <I>object</I><P>
<P>
<P><B>Method Signatures:</B><P>
<P>
<B>print-object</B> <I>(<I>object</I> standard-object) <I>stream</I></I><P>
<B>print-object</B> <I>(<I>object</I> structure-object) <I>stream</I></I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>object</I>---an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
<I>stream</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A>. <P>
<P><B>Description:</B><P>
<P>
The <A REL=DEFINITION HREF="26_glo_g.htm#generic_function"><I>generic function</I></A> <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> writes the printed representation of <I>object</I> to <I>stream</I>. The <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> is called by the <A REL=DEFINITION HREF="26_glo_l.htm#lisp_printer"><I>Lisp printer</I></A>; it should not be called by the user. <P>
Each implementation is required to provide a <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> on the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> <A REL=DEFINITION HREF="t_std_ob.htm#standard-object"><B>standard-object</B></A> and on the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> <A REL=DEFINITION HREF="t_stu_ob.htm#structure-object"><B>structure-object</B></A>. In addition, each <A REL=DEFINITION HREF="26_glo_i.htm#implementation"><I>implementation</I></A> must provide <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> on enough other <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>classes</I></A> so as to ensure that there is always an applicable <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A>. Implementations are free to add <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> for other <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>classes</I></A>. Users may write <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> for <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> for their own <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>classes</I></A> if they do not wish to inherit an <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A> <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A>. <P>
The <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> on the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> <A REL=DEFINITION HREF="t_stu_ob.htm#structure-object"><B>structure-object</B></A> prints the object in the default <TT>#S</TT> notation; see <A REL=CHILD HREF="22_acl.htm">Section 22.1.3.12 (Printing Structures)</A>. <P>
<A REL=DEFINITION HREF="26_glo_m.htm#method"><I>Methods</I></A> on <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> are responsible for implementing their part of the semantics of the <A REL=DEFINITION HREF="26_glo_p.htm#printer_control_variable"><I>printer control variables</I></A>, as follows: <P>
<P><DL><P>
<P>
<DT><A REL=DEFINITION HREF="v_pr_rda.htm#STprint-readablyST"><B>*print-readably*</B></A> <P><DD>
All methods for <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> must obey <A REL=DEFINITION HREF="v_pr_rda.htm#STprint-readablyST"><B>*print-readably*</B></A>. This includes both user-defined methods and <A REL=DEFINITION HREF="26_glo_i.htm#implementation-defined"><I>implementation-defined</I></A> methods. Readable printing of <A REL=DEFINITION HREF="26_glo_s.htm#structure"><I>structures</I></A> and <A REL=DEFINITION HREF="26_glo_s.htm#standard_object"><I>standard objects</I></A> is controlled by their <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> method, not by their <A REL=DEFINITION HREF="f_mk_ld_.htm#make-load-form"><B>make-load-form</B></A> <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A>. <A REL=DEFINITION HREF="26_glo_s.htm#similarity"><I>Similarity</I></A> for these <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> is application dependent and hence is defined to be whatever these <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> do; see <A REL=CHILD HREF="03_bdb.htm">Section 3.2.4.2 (Similarity of Literal Objects)</A>. <P>
<P>
<DT><A REL=DEFINITION HREF="v_pr_esc.htm#STprint-escapeST"><B>*print-escape*</B></A> <P><DD>
Each <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> must implement <A REL=DEFINITION HREF="v_pr_esc.htm#STprint-escapeST"><B>*print-escape*</B></A>. <P>
<DT><A REL=DEFINITION HREF="v_pr_pre.htm#STprint-prettyST"><B>*print-pretty*</B></A> <P><DD>
The <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> may wish to perform specialized line breaking or other output conditional on the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of <A REL=DEFINITION HREF="v_pr_pre.htm#STprint-prettyST"><B>*print-pretty*</B></A>. For further information, see (for example) the <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macro</I></A> <A REL=DEFINITION HREF="f_ppr_fi.htm#pprint-fill"><B>pprint-fill</B></A>. See also <A REL=CHILD HREF="22_bad.htm">Section 22.2.1.4 (Pretty Print Dispatch Tables)</A> and <A REL=CHILD HREF="22_bb.htm">Section 22.2.2 (Examples of using the Pretty Printer)</A>. <P>
<DT><A REL=DEFINITION HREF="v_pr_lev.htm#STprint-lengthST"><B>*print-length*</B></A> <P><DD>
<A REL=DEFINITION HREF="26_glo_m.htm#method"><I>Methods</I></A> that produce output of indefinite length must obey <A REL=DEFINITION HREF="v_pr_lev.htm#STprint-lengthST"><B>*print-length*</B></A>. For further information, see (for example) the <A REL=DEFINITION HREF="26_glo_m.htm#macro"><I>macros</I></A> <A REL=DEFINITION HREF="m_ppr_lo.htm#pprint-logical-block"><B>pprint-logical-block</B></A> and <A REL=DEFINITION HREF="m_ppr_po.htm#pprint-pop"><B>pprint-pop</B></A>. See also <A REL=CHILD HREF="22_bad.htm">Section 22.2.1.4 (Pretty Print Dispatch Tables)</A> and <A REL=CHILD HREF="22_bb.htm">Section 22.2.2 (Examples of using the Pretty Printer)</A>. <P>
<DT><A REL=DEFINITION HREF="v_pr_lev.htm#STprint-levelST"><B>*print-level*</B></A> <P><DD>
The printer takes care of <A REL=DEFINITION HREF="v_pr_lev.htm#STprint-levelST"><B>*print-level*</B></A> automatically, provided that each <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> handles exactly one level of structure and calls <A REL=DEFINITION HREF="f_wr_pr.htm#write"><B>write</B></A> (or an equivalent <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A>) recursively if there are more structural levels. The printer's decision of whether an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A> has components (and therefore should not be printed when the printing depth is not less than <A REL=DEFINITION HREF="v_pr_lev.htm#STprint-levelST"><B>*print-level*</B></A>) is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A>. In some implementations its <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> is not called; in others the <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> is called, and the determination that the <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A> has components is based on what it tries to write to the <I>stream</I>. <P>
<DT><A REL=DEFINITION HREF="v_pr_cir.htm#STprint-circleST"><B>*print-circle*</B></A> <P><DD>
When the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of <A REL=DEFINITION HREF="v_pr_cir.htm#STprint-circleST"><B>*print-circle*</B></A> is <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A>, a user-defined <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> can print <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> to the supplied <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A> using <A REL=DEFINITION HREF="f_wr_pr.htm#write"><B>write</B></A>, <A REL=DEFINITION HREF="f_wr_pr.htm#prin1"><B>prin1</B></A>, <A REL=DEFINITION HREF="f_wr_pr.htm#princ"><B>princ</B></A>, or <A REL=DEFINITION HREF="f_format.htm#format"><B>format</B></A> and expect circularities to be detected and printed using the <TT>#</TT><I>n</I><TT>#</TT> syntax. If a user-defined <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> prints to a <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A> other than the one that was supplied, then circularity detection starts over for that <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A>. See <A REL=DEFINITION HREF="v_pr_cir.htm#STprint-circleST"><B>*print-circle*</B></A>. <P>
<DT><A REL=DEFINITION HREF="v_pr_bas.htm#STprint-baseST"><B>*print-base*</B></A>, <A REL=DEFINITION HREF="v_pr_bas.htm#STprint-radixST"><B>*print-radix*</B></A>, <A REL=DEFINITION HREF="v_pr_cas.htm#STprint-caseST"><B>*print-case*</B></A>, <A REL=DEFINITION HREF="v_pr_gen.htm#STprint-gensymST"><B>*print-gensym*</B></A>, and <A REL=DEFINITION HREF="v_pr_ar.htm#STprint-arrayST"><B>*print-array*</B></A> <P><DD>
These <A REL=DEFINITION HREF="26_glo_p.htm#printer_control_variable"><I>printer control variables</I></A> apply to specific types of <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> and are handled by the <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> for those <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A>. <P>
<P></DL><P>
If these rules are not obeyed, the results are undefined. <P>
In general, the printer and the <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> methods should not rebind the print control variables as they operate recursively through the structure, but this is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A>. <P>
In some implementations the <I>stream</I> argument passed to a <A REL=DEFINITION HREF="#print-object"><B>print-object</B></A> <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>method</I></A> is not the original <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A>, but is an intermediate <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A> that implements part of the printer. <A REL=DEFINITION HREF="26_glo_m.htm#method"><I>methods</I></A> should therefore not depend on the identity of this <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A>. <P>
<P><B>Examples:</B> None.
<P>
<P><B>Affected By:</B> None.
<P>
<P><B>Exceptional Situations:</B> None.
<P>
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="f_ppr_fi.htm#pprint-fill"><B>pprint-fill</B></A>, <A REL=DEFINITION HREF="m_ppr_lo.htm#pprint-logical-block"><B>pprint-logical-block</B></A>, <A REL=DEFINITION HREF="m_ppr_po.htm#pprint-pop"><B>pprint-pop</B></A>, <A REL=DEFINITION HREF="f_wr_pr.htm#write"><B>write</B></A>, <A REL=DEFINITION HREF="v_pr_rda.htm#STprint-readablyST"><B>*print-readably*</B></A>, <A REL=DEFINITION HREF="v_pr_esc.htm#STprint-escapeST"><B>*print-escape*</B></A>, <A REL=DEFINITION HREF="v_pr_pre.htm#STprint-prettyST"><B>*print-pretty*</B></A>, <A REL=DEFINITION HREF="v_pr_lev.htm#STprint-lengthST"><B>*print-length*</B></A>, <A REL=CHILD HREF="22_ac.htm">Section 22.1.3 (Default Print-Object Methods)</A>, <A REL=CHILD HREF="22_acl.htm">Section 22.1.3.12 (Printing Structures)</A>, <A REL=CHILD HREF="22_bad.htm">Section 22.2.1.4 (Pretty Print Dispatch Tables)</A>, <A REL=CHILD HREF="22_bb.htm">Section 22.2.2 (Examples of using the Pretty Printer)</A> <P>
<P><B>Notes:</B> None.
<P>
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss275.htm">PRINT-CIRCLE-STRUCTURE:USER-FUNCTIONS-WORK</A><LI> <A REL=CHILD HREF="../Issues/iss180.htm">GENERALIZE-PRETTY-PRINTER:UNIFY</A><LI> <A REL=CHILD HREF="../Issues/iss089.htm">DATA-IO:ADD-SUPPORT</A><LI> <A REL=CHILD HREF="../Issues/iss116.htm">DEFSTRUCT-PRINT-FUNCTION-AGAIN:X3J13-MAR-93</A><P></UL><HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>