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

157 lines
8.2 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-DEFAULT-VALUE-EVALUATION 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/iss113_w.htm">
<LINK REL=UP HREF="../Issues/iss114.htm">
<LINK REL=NEXT HREF="../Issues/iss115_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/iss113_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss114.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss115_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue DEFSTRUCT-DEFAULT-VALUE-EVALUATION Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss114.htm">DEFSTRUCT-DEFAULT-VALUE-EVALUATION</A><P>
<B>References:</B> CLtL p.308-10 &amp; 86-003 p.4<P>
<B>Category:</B> CLARIFICATION<P>
<B>Edit history:</B> Revision 1 by Skona Brittain 05/13/88<P>
<P>
<P>
<B>Problem Description:<P>
</B><P>
There is some confusion over whether default initialization<P>
forms for <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> slots get evaluated, when they are not needed<P>
because a keyword argument was supplied to the constructor function.<P>
As a consequence of this confusion, there is confusion over whether<P>
there can be a type-mismatch error between the specified type of the slot<P>
and the type of the default value.<P>
<P>
On page 308, it says &quot;The default-init is a form that is evaluated <P>
each time a <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> is to be constructed; the value is used as the <P>
initial value of the slot. If no default-init is specified, then the<P>
initial contents of the slot are undefined and implementation-dependent.&quot;<P>
<P>
On the next page, however, it says that the default-init is evaluated if<P>
the keyword argument is not supplied and the converse, although not stated,<P>
is intended and informally implied.<P>
<P>
<P>
<B>Proposal (DEFSTRUCT-DEFAULT-VALUE-EVALUATION:IFF-NEEDED):<P>
</B><P>
Clarify that the converse is true. i.e that the default-init is not evaluated <P>
if the keyword argument is supplied.<P>
<P>
In the quote from page 308, delete the second sentence and replace <P>
&quot;a <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> is to be constructed; the value is&quot; by &quot;its value is to be&quot;.<P>
<P>
To section 19.3, add a clarification,<P>
such as the following from Guy's issues file:<P>
&quot;The default value in a <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> slot is not evaluated <P>
unless it is needed in the creation of a particular <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A><P>
instance. If it is never needed, there can be no type-mismatch<P>
error, even if the type of the slot is specified, and no warning<P>
should be issued.&quot;<P>
<P>
<P>
<B>Test Case:<P>
</B><P>
In the following sequence, only the last call is an error.<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> person (name 007 :type <A REL=DEFINITION HREF="../Body/a_string.htm#string"><B>string</B></A>)) <P>
(make-person :name &quot;James&quot;)<P>
(make-person)<P>
<P>
<P>
<B>Rationale:<P>
</B><P>
It is inefficient, and inconsistent with the rest of the language, for the <P>
default initialization form to be evaluated when it is not needed.<P>
Consequently, when it's not needed, such type-mismatch errors should not be <P>
detectable in general.<P>
<P>
Any existing confusion should be clarified by this proposal.<P>
<P>
<P>
<B>Current Practice:<P>
</B><P>
KCL does not evaluate the default initialization form unless it is needed;<P>
even when it is needed, the type checking is not done at all.<P>
<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
If there are any implementations that currently behave differently from<P>
the proposed way, then they need some slight modification. <P>
<P>
<P>
<B>Cost to Users:<P>
</B><P>
None.<P>
<P>
<P>
<B>Benefits:<P>
</B><P>
Clarity and portability. In particular, clarifying that the unaesthetic <P>
situation mentioned in the next section is allowed should be reassuring.<P>
<P>
<P>
<B>Aesthetics:<P>
</B><P>
It appears slightly unaesthetic to have a default value that violates a <P>
type specification. <P>
<P>
<P>
<B>Discussion: <P>
</B><P>
Although this issue was mentioned in Guy's original issues file, it has<P>
not been officially discussed since.<P>
<P>
!<P>
Additional notes:<P>
<P>
Several members of the cleanup committee endorsed this proposal.<P>
<P>
JonL added:<P>
<P>
You can add to the &quot;Current Practice:&quot; section:<P>
<P>
LUCID does not evaluate the default initialization form unless it is <P>
needed; even when it is needed, the type checking is not done at all.<P>
However, at <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> definition time, if an initial value form is<P>
constanp and doesn't satisfy the :type specification, a warning message<P>
is printed.<P>
<P>
Oddly enough, Lucid's interpreter ensures that <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A>'s of slots obey the<P>
:type specifier, even though init-forms aren't checked. Furthermore, in <P>
safety levels 2 or higher, the compiled code will do minimal &quot;memory-<P>
integrity&quot; type checking for <A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>SETF</B></A>'s (which is what I suspect the various <P>
special-purpose microcoded machines do); however except for low-level numeric<P>
types, this is rarely equivalent to what a full type check would do.<P>
<P>
I have long suggested that there should be at least one mode of operation <P>
such that all :type information is checked when setting values into <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A><P>
slots (<A REL=DEFINITION HREF="../Body/a_setf.htm#setf"><B>setf</B></A> as well as initialization). Some have suggested that this mode <P>
could be &quot;when running interpretively, or when when compiled with the highest<P>
degree of <A REL=DEFINITION HREF="../Body/d_optimi.htm#safety"><B>SAFETY</B></A> and lower degrees of <A REL=DEFINITION HREF="../Body/d_optimi.htm#speed"><B>SPEED</B></A>.&quot; However, since the wording of <P>
CLtL p310 suggests that the :type slot options is merely a <A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A>, and since<P>
some vendors effectively ignore any and all declarations [except for SPECIAL],<P>
then this suggestion hasn't reached proposal stage yet.<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>