164 lines
10 KiB
HTML
164 lines
10 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: Issue DEFSTRUCT-PRINT-FUNCTION-AGAIN Writeup</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="../Issues/iss115_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss116.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss117_w.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="../Issues/iss115_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss116.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss117_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue DEFSTRUCT-PRINT-FUNCTION-AGAIN Writeup</H2>
|
|
|
|
<PRE><B>Forum:</B> Public Review<P>
|
|
<B>Issue:</B> <A HREF="iss116.htm">DEFSTRUCT-PRINT-FUNCTION-AGAIN</A><P>
|
|
<B>References:</B> Loosemore's public review comment #25 (X3J13/92-1325)<P>
|
|
Norvig's public review comment #8.1 (X3J13/92-2208)<P>
|
|
Pitman's public review comment #7 (X3J13/92-2707)<P>
|
|
Issue <A HREF="iss117.htm">DEFSTRUCT-PRINT-FUNCTION-INHERITANCE</A><P>
|
|
<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> :PRINT-FUNCTION option (p 8-10 and 8-11)<P>
|
|
<A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A> (p 22-55)<P>
|
|
<B>Category:</B> CHANGE<P>
|
|
<B>Edit history:</B> 24 Dec 1992, Version 1 by Loosemore<P>
|
|
01 Jan 1993, Version 2 by Loosemore (fix references,<P>
|
|
add <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> signature for <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>print-object</B></A>)<P>
|
|
<B>Status:</B> Parts (2),(3),(4) only passed 6-1, March 1993<P>
|
|
<P>
|
|
<P>
|
|
<B>Problem description:<P>
|
|
</B><P>
|
|
Supplying the :PRINT-FUNCTION option to <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> is supposed to<P>
|
|
be equivalent to defining a <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A> <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A>, but the two can't<P>
|
|
be entirely equivalent since the :PRINT-FUNCTION takes a third<P>
|
|
argument (the current recursive printing depth) that the <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A><P>
|
|
<A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> does not.<P>
|
|
<P>
|
|
It is also not clear whether the inheritance of <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> <P>
|
|
:PRINT-FUNCTIONs by the :INCLUDE option works in such a way that<P>
|
|
one may use <A REL=DEFINITION HREF="../Body/f_call_n.htm#call-next-method"><B>CALL-NEXT-METHOD</B></A> and the like.<P>
|
|
<P>
|
|
<P>
|
|
<B>Proposal (DEFSTRUCT-PRINT-FUNCTION-AGAIN:REPLACE-OPTION):<P>
|
|
</B><P>
|
|
(1) Remove the :PRINT-FUNCTION option to <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A>.<P>
|
|
<P>
|
|
(2) Add a new <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> option, :PRINT-OBJECT, and document it<P>
|
|
as follows:<P>
|
|
<P>
|
|
This option can be used only if :TYPE is not supplied. The<P>
|
|
argument to :PRINT-OBJECT should be in a form acceptable to<P>
|
|
<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A>, and is used when printing structures of this type.<P>
|
|
The function is called with two arguments: the <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> to <P>
|
|
be printed and the stream to print to.<P>
|
|
<P>
|
|
Supplying (:PRINT-OBJECT fn) in a <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> definition for<P>
|
|
a <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> named s is equivalent to executing<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_defmet.htm#defmethod"><B>defmethod</B></A> <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>print-object</B></A> ((object s) <A REL=DEFINITION HREF="../Body/t_stream.htm#stream"><B>stream</B></A>)<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_funcal.htm#funcall"><B>funcall</B></A> (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>function</B></A> fn) object <A REL=DEFINITION HREF="../Body/t_stream.htm#stream"><B>stream</B></A>))<P>
|
|
<P>
|
|
The :PRINT-OBJECT option can also be supplied without an<P>
|
|
argument. This is equivalent to defining a <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A><P>
|
|
<A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> which calls a function that prints the <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> in<P>
|
|
the default #S notation. [Kent Pitman's comment #7 proposes<P>
|
|
to name this function PRINT-OBJECT-USING-SLOTS.]<P>
|
|
<P>
|
|
If no :PRINT-OBJECT option is provided, then <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> does<P>
|
|
not generate a <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A> <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> specialized on the named<P>
|
|
<A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> <A REL=DEFINITION HREF="../Body/t_class.htm#class"><B>class</B></A>.<P>
|
|
<P>
|
|
(3) Change places in chapter 22 that refer to "print functions"<P>
|
|
to refer to "PRINT-OBJECT methods" instead.<P>
|
|
<P>
|
|
(4) Add to the "Method Signatures" section for PRINT-OBJECT:<P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>print-object</B></A> (object <A REL=DEFINITION HREF="../Body/t_stu_ob.htm#structure-object"><B>structure-object</B></A>) stream<P>
|
|
<P>
|
|
In the "Description" section for <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A>, state that the<P>
|
|
<A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> on the <A REL=DEFINITION HREF="../Body/t_class.htm#class"><B>class</B></A> <A REL=DEFINITION HREF="../Body/t_stu_ob.htm#structure-object"><B>structure-object</B></A> prints the object in the<P>
|
|
default #S notation as described in section 22.1.3.15.<P>
|
|
<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B><P>
|
|
The addition of <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A> and the pretty-printing protocol makes<P>
|
|
it clear that <A REL=DEFINITION HREF="../Body/v_pr_lev.htm#STprint-levelST"><B>*PRINT-LEVEL*</B></A> truncation is handled automatically by<P>
|
|
the printer, so the third argument to :PRINT-FUNCTION functions is<P>
|
|
useless.<P>
|
|
<P>
|
|
Simply redefining :PRINT-FUNCTION to take functions of two arguments<P>
|
|
rather than of three would break existing programs. Replacing it<P>
|
|
with a new option with a different name permits implementations to <P>
|
|
continue to support the old :PRINT-FUNCTION as an extension, and/or <P>
|
|
issue diagnostics about obsolete usages.<P>
|
|
<P>
|
|
Specifying the behavior of :PRINT-OBJECT entirely in terms of<P>
|
|
<A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A> and normal <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> definition means that the <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A><P>
|
|
doesn't have to discuss :PRINT-OBJECT functions as a special case.<P>
|
|
This makes the <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> conceptually simpler.<P>
|
|
<P>
|
|
<P>
|
|
<B>Current practice:<P>
|
|
</B><P>
|
|
Nobody ever does anything useful with the third argument to<P>
|
|
:PRINT-FUNCTION functions anyway.<P>
|
|
<P>
|
|
<P>
|
|
<B>Cost to implementors:<P>
|
|
</B><P>
|
|
Some implementations will doubtless have to change, but the addition<P>
|
|
of the <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A> and pretty-printer protocols already means that<P>
|
|
many implementations will have to rework their printers anyway.<P>
|
|
<P>
|
|
<P>
|
|
<B>Cost to users:<P>
|
|
</B><P>
|
|
This is an incompatible change, but one that can be detected <P>
|
|
easily. Implementations may continue to support :PRINT-FUNCTION<P>
|
|
as an extension for backward compatibility.<P>
|
|
<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
I like it.<P>
|
|
<P>
|
|
<P>
|
|
<B>Editorial impact:<P>
|
|
</B><P>
|
|
The references to :PRINT-FUNCTION in the structures and printers<P>
|
|
chapters will have to be changed.<P>
|
|
<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
Barrett notes that the description for the <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A> <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> on<P>
|
|
<A REL=DEFINITION HREF="../Body/t_std_ob.htm#standard-object"><B>standard-object</B></A> doesn't say anything about how it actually prints<P>
|
|
the objects. Presumably this is covered by section 22.1.3.16, which<P>
|
|
says that "other objects are printed in an implementation-dependent<P>
|
|
manner".<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
</PRE>
|
|
<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>
|