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

106 lines
5.9 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-INHERITANCE 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/iss116_w.htm">
<LINK REL=UP HREF="../Issues/iss117.htm">
<LINK REL=NEXT HREF="../Issues/iss118_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/iss116_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss117.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss118_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue DEFSTRUCT-PRINT-FUNCTION-INHERITANCE Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss117.htm">DEFSTRUCT-PRINT-FUNCTION-INHERITANCE</A><P>
<B>References:</B> CLtL p. 312-314<P>
<B>Category:</B> CLARIFICATION<P>
<B>Edit History:</B> V1, 5 Aug 1988, Sandra Loosemore<P>
V2, 15 Sep 1988, Sandra Loosemore<P>
V3, 7 Dec 1988, Masinter<P>
<P>
<B>Problem Description:<P>
</B><P>
CLtL doesn't make clear whether defstructs that :INCLUDE another<P>
<A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> type and do not specify a :PRINT-FUNCTION inherit the<P>
:PRINT-FUNCTION of the parent <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> type. While it is stated on<P>
page 314 that #S syntax is used if a :PRINT-FUNCTION is not specified,<P>
the language on page 313 indicates that all operations on the parent<P>
type will also work on objects of the child type. Because of the<P>
ambiguity, existing implementations have gone both ways, and users<P>
cannot depend on either #S syntax or the parent type's :PRINT-FUNCTION<P>
being used.<P>
<P>
Proposal: <A HREF="iss117.htm">DEFSTRUCT-PRINT-FUNCTION-INHERITANCE:YES</A><P>
<P>
Clarify that <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> types which :INCLUDE another type but do not<P>
specify an explicit :PRINT-FUNCTION inherit the <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> print<P>
function from the :INCLUDE'd type. A print function that uses the<P>
default #S syntax (overriding any print function for the parent type)<P>
can be specified by providing the :PRINT-FUNCTION option without an <P>
argument.<P>
<P>
Supplying a :PRINT-FUNCTION in a <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> is equivalent<P>
to defining an appropriate <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> on the <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A> generic<P>
function.<P>
<P>
<B>Rationale:<P>
</B><P>
Users typically specify a print function for a <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> type because<P>
its slots will contain circular objects or large internal data<P>
structures which are confusing when printed. Any <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> type that<P>
:INCLUDEs this type will also contain the same slots; it seems more<P>
reasonable to inherit the parent's print function than to use the<P>
default #S syntax.<P>
<P>
<B>Current Practice:<P>
</B><P>
Lucid Common Lisp makes structures inherit print functions.<P>
VaxLisp uses #S syntax unless an explicit :PRINT-FUNCTION<P>
is specified.<P>
<P>
<B>Cost to implementors:<P>
</B><P>
The changes to non-conforming implementations should be fairly minor<P>
and localized.<P>
<P>
<P>
<B>Cost to users:<P>
</B><P>
It can't be any worse than the status quo.<P>
<P>
<P>
<B>Benefits:<P>
</B><P>
An area of ambiguity in the language will be removed.<P>
<P>
<P>
<B>Discussion:<P>
</B><P>
Pitman and VanRoggen support this proposal.<P>
<P>
The original version of the proposal did not <A REL=DEFINITION HREF="../Body/f_provid.htm#provide"><B>provide</B></A> for a way to<P>
force #S syntax to be used. This functionality was added to the<P>
current version because there seemed to be general agreement that it<P>
would be useful. Other alternatives would be to name the function<P>
that does what the #S printer does, or to <A REL=DEFINITION HREF="../Body/f_provid.htm#provide"><B>provide</B></A> a function that<P>
returns the #S information as a list (as suggested by Waters) so users<P>
can write their own.<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>