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

183 lines
9.4 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-COPIER 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/iss112_w.htm">
<LINK REL=UP HREF="../Issues/iss113.htm">
<LINK REL=NEXT HREF="../Issues/iss114_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/iss112_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss113.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss114_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue DEFSTRUCT-COPIER Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss113.htm">DEFSTRUCT-COPIER</A><P>
<B>References:</B> <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A><P>
<B>Related issues:<P>
</B><B>Category:</B> CLARIFICATION, CHANGE<P>
<B>Edit history:</B> V1, 10 May 90, Sandra Loosemore<P>
V2, 13 May 90, Sandra Loosemore (update discussion)<P>
V3, 29 May 90, Sandra Loosemore (more comments)<P>
<P>
<B>Problem description:<P>
</B><P>
The description of the :COPIER option to <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> in CLtL<P>
states:<P>
<P>
The automatically defined copier function simply makes a new<P>
<A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> and transfers all components verbatim from the argument<P>
into the newly created <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A>.<P>
<P>
This description doesn't make it clear whether the type of the<P>
newly created <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> is copied from the argument, or is<P>
determined by the copier function. This can make a difference<P>
in the case where a copier function defined for one <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A><P>
type is passed an argument that belongs to a subtype of the<P>
original type. Does the result have the &quot;name&quot; of the subtype<P>
and any additional slots present in the subtype but not the<P>
parent type, or does it have the same &quot;name&quot; as the parent <P>
type and only the slots inherited from that type?<P>
<P>
There are four proposals: ARGUMENT-TYPE, COPIER-TYPE,<P>
UNSPECIFIED, and <A REL=DEFINITION HREF="../Body/f_rm_rm.htm#remove"><B>REMOVE</B></A>.<P>
<P>
<P>
<B>Proposal (DEFSTRUCT-COPIER:ARGUMENT-TYPE):<P>
</B><P>
Clarify that the type of the result returned by copier functions <P>
created by <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> is always exactly the same type as the <P>
argument to the copier. That is, if the argument is of a<P>
subtype of the <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> type for which the copier was defined,<P>
then the result will also be of that subtype and include all<P>
the slots of the subtype.<P>
<P>
Rationale for proposal ARGUMENT-TYPE:<P>
Some people expect this behavior.<P>
<P>
<P>
<B>Proposal (DEFSTRUCT-COPIER:COPIER-TYPE):<P>
</B><P>
Clarify that the type of the result returned by copier functions <P>
created by <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> is always exactly the <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> type for <P>
which the copier was defined. That is, if the argument is of a<P>
subtype of the <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> type for which the copier was defined,<P>
the result will be of the supertype only and include only those<P>
slots that are present in the supertype.<P>
<P>
Rationale for proposal COPIER-TYPE:<P>
Some people expect this behavior.<P>
<P>
<P>
<B>Proposal (DEFSTRUCT-COPIER:UNSPECIFIED):<P>
</B><P>
Clarify that it is unspecified whether the type of the result <P>
returned by copier functions created by <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> is the type<P>
of the argument to the copier, or the <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> type for which the<P>
copier function was defined. (In other words, the behavior of<P>
copier functions is well-defined only when they are passed<P>
arguments of the exact same type for which the copier was<P>
defined.)<P>
<P>
Rationale for proposal UNSPECIFIED:<P>
Some people don't know what behavior to expect.<P>
<P>
<P>
<B>Proposal (DEFSTRUCT-COPIER:REMOVE):<P>
</B><P>
Remove the :COPIER option to <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A>.<P>
<P>
Rationale for proposal REMOVE:<P>
The feature is so poorly specified it's already useless.<P>
<P>
<P>
<B>Examples:<P>
</B><P>
(<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> foo a b)<P>
(<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> (bar (:include foo)) c d)<P>
(<A REL=DEFINITION HREF="../Body/s_setq.htm#setq"><B>setq</B></A> result (copy-foo (make-bar)))<P>
<P>
Under proposal ARGUMENT-TYPE,<P>
(<A REL=DEFINITION HREF="../Body/f_tp_of.htm#type-of"><B>type-of</B></A> result) =&gt; BAR<P>
<P>
Under proposal COPIER-TYPE,<P>
(<A REL=DEFINITION HREF="../Body/f_tp_of.htm#type-of"><B>type-of</B></A> result) =&gt; FOO<P>
<P>
Under proposal UNSPECIFIED,<P>
(<A REL=DEFINITION HREF="../Body/f_tp_of.htm#type-of"><B>type-of</B></A> result) =&gt; either FOO or BAR<P>
<P>
Under proposal <A REL=DEFINITION HREF="../Body/f_rm_rm.htm#remove"><B>REMOVE</B></A>, users would have to define their own<P>
copier functions to have whatever behavior they wanted.<P>
<P>
<P>
<B>Current Practice:<P>
</B><P>
Some Lisps now implement proposal ARGUMENT-TYPE and others implement <P>
proposal COPIER-TYPE. Some Lisps also <A REL=DEFINITION HREF="../Body/f_provid.htm#provide"><B>provide</B></A> a <A REL=DEFINITION HREF="../Body/f_cp_stu.htm#copy-structure"><B>COPY-STRUCTURE</B></A><P>
function that can be used to make an exact duplicate of any<P>
<A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> object.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Small.<P>
<P>
<B>Cost to Users:<P>
</B><P>
Code that relies on any particular behavior is probably not now<P>
portable anyway. It doesn't seem like copiers are used very<P>
much.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
This part of the language specification remains vague.<P>
<P>
<B>Performance impact:<P>
</B><P>
Proposal <A REL=DEFINITION HREF="../Body/f_rm_rm.htm#remove"><B>REMOVE</B></A> would save space since there would be no<P>
normally useless copier functions generated by <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A>.<P>
It may be that copier functions defined by hand would be<P>
considerably less efficient than a copier provided by the<P>
implementation (which might make use of knowledge about the<P>
internal layout of structures to do a block memory copy or the<P>
like).<P>
<P>
<B>Benefits:<P>
</B><P>
This part of the language specification becomes more precise.<P>
<P>
<B>Esthetics:<P>
</B><P>
Leaving the behavior explicitly vague seems unnecessarily ugly.<P>
<P>
<B>Discussion:<P>
</B><P>
Loosemore's ranking of the proposals from most to least<P>
acceptable is: ARGUMENT-TYPE, <A REL=DEFINITION HREF="../Body/f_rm_rm.htm#remove"><B>REMOVE</B></A>, COPIER-TYPE,<P>
UNSPECIFIED.<P>
<P>
BarMar has said he thinks the behavior should be left<P>
unspecified.<P>
<P>
Moon has said he favors flushing the :copier feature. Barrett<P>
also prefers flushing :copier.<P>
<P>
Perhaps we should consider adding <A REL=DEFINITION HREF="../Body/f_cp_stu.htm#copy-structure"><B>COPY-STRUCTURE</B></A> to the<P>
standard?<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>