1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Issues/iss197_w.htm

225 lines
15 KiB
HTML
Raw Permalink Normal View History

2024-04-01 10:24:07 +02:00
<!-- 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 INITIALIZATION-FUNCTION-KEYWORD-CHECKING 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/iss196_w.htm">
<LINK REL=UP HREF="../Issues/iss197.htm">
<LINK REL=NEXT HREF="../Issues/iss198_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/iss196_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss197.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss198_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue INITIALIZATION-FUNCTION-KEYWORD-CHECKING Writeup</H2>
<PRE><B>Status:</B> Passed v4 (8-1), as amended, Dec-91; v5 reflects the amendment<P>
<B>Issue:</B> <A HREF="iss197.htm">INITIALIZATION-FUNCTION-KEYWORD-CHECKING</A><P>
Reference: Draft 10.156<P>
7.2.1.1 Initialization Arguments (p.7-6)<P>
(which corresponds to CLtL-II 28.1.9.1, p.802)<P>
7.2.1.2 Declaring the Validity of Initialization Arguments<P>
(p.7-7) (which corresponds to CLtL-II 28.1.9.2, p.803)<P>
7.3.5 Keyword Arguments in Generic Functions and Methods<P>
(p.7-20) (which corresponds to CLtL-II 28.1.6.5, p.792)<P>
<B>Category:</B> CHANGE<P>
<B>Edit History:</B> Version 1, 10/2/91, Kim Barrett<P>
Version 2, 10/8/91, Kim Barrett (Moon &amp; JonL comments)<P>
Version 3, 10/11/91, Kim Barrett (more Moon comments)<P>
Version 4, 11/20/91, Kim Barrett<P>
(clarify :allow-other-keys, make references to 10.156 draft)<P>
Version 5, 11-Feb-92, Kent Pitman<P>
(&quot;has no effect on&quot; =&gt; &quot;suppresses&quot; per X3J13 meeting amendment)<P>
<P>
<B>Problem Description:<P>
</B><P>
A careful reading of 88-002R indicates that users must specify<P>
<A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in the lambda-lists of methods for initialization functions<P>
if the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> also specifies <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A>, else risk having the generic function<P>
keyword argument checking signal an error due to the presence of &quot;slot<P>
filling&quot; initargs. (An error might not occur due to the presence of other<P>
methods which already specify <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> + <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A>).<P>
<P>
Several implementors (and presumably users too) have misread the specification<P>
as saying that <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in an applicable initialization <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> means<P>
that initarg validation is suppressed for those protocols in which the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A><P>
takes part.<P>
<P>
The result is that the need for and meaning of <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in<P>
initialization methods differs significantly from one implementation to<P>
another. <P>
<P>
<B>Proposal:<P>
</B><P>
1. Change the syntax of the following generic functions to specify both <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A><P>
and &amp;ALLOW-OTHER-KEYS:<P>
<P>
<A REL=DEFINITION HREF="../Body/f_alloca.htm#allocate-instance"><B>ALLOCATE-INSTANCE</B></A> <A REL=DEFINITION HREF="../Body/t_class.htm#class"><B>class</B></A> &amp;key &amp;allow-other-keys<P>
<A REL=DEFINITION HREF="../Body/f_init_i.htm#initialize-instance"><B>INITIALIZE-INSTANCE</B></A> object &amp;key &amp;allow-other-keys<P>
<A REL=DEFINITION HREF="../Body/f_mk_ins.htm#make-instance"><B>MAKE-INSTANCE</B></A> <A REL=DEFINITION HREF="../Body/t_class.htm#class"><B>class</B></A> &amp;key &amp;allow-other-keys<P>
<A REL=DEFINITION HREF="../Body/f_reinit.htm#reinitialize-instance"><B>REINITIALIZE-INSTANCE</B></A> object &amp;key &amp;allow-other-keys<P>
<A REL=DEFINITION HREF="../Body/f_shared.htm#shared-initialize"><B>SHARED-INITIALIZE</B></A> object slot-names &amp;key &amp;allow-other-keys<P>
<A REL=DEFINITION HREF="../Body/f_update.htm#update-instance-for-different-class"><B>UPDATE-INSTANCE-FOR-DIFFERENT-CLASS</B></A> previous current<P>
&amp;key &amp;allow-other-keys<P>
<A REL=DEFINITION HREF="../Body/f_upda_1.htm#update-instance-for-redefined-class"><B>UPDATE-INSTANCE-FOR-REDEFINED-CLASS</B></A> object<P>
added-slots discarded-slots<P>
property-list<P>
&amp;key &amp;allow-other-keys<P>
<P>
It is of course possible to retain &quot;&amp;rest initargs&quot; in the syntax description<P>
when needed in the corresponding function description.<P>
<P>
2. Clarify that the presence of <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in the lambda-list of an<P>
applicable <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> relevant to the specified initarg validity checking for an<P>
initialization protocol suppresses the validity checking.<P>
<P>
3. Clarify that a true value for the initialization argument :ALLOW-OTHER-KEYS<P>
disables initialization argument validation. Make the following changes Draft<P>
10.156 in order make this clarification.<P>
<P>
a. Remove the last sentence of the second paragraph of section 7.2.1.1<P>
(p.7-6), which says<P>
<P>
&quot;Error checking of initialization argument names is disabled if the keyword<P>
argument pair whose keyword is :ALLOW-OTHER-KEYS and whose value is non-NIL<P>
appears in the initialization argument list.&quot;<P>
<P>
b. Replace the last sentence of section 7.2.1.2 (p.7-7), which says<P>
<P>
&quot;The meaning of:ALLOW-OTHER-KEYS is the same here as when it is passed to an<P>
ordinary function.&quot;<P>
<P>
with<P>
<P>
&quot;Validity checking of initialization arguments is disabled if the value of<P>
the initialization argument :ALLOW-OTHER-KEYS is true.&quot;<P>
<P>
<B>Editorial impact:<P>
</B><P>
The syntax entries for seven functions need to be modified.<P>
<P>
A small change to &quot;Declaring the Validity of Initialization Arguments&quot; is<P>
needed in order to clarify the handling of <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in initialization <P>
methods.<P>
<P>
<B>Rationale:<P>
</B><P>
Since <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> needs to be specified somewhere if <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> is specified<P>
by any of the applicable methods, it is better to have the generic function<P>
specify it, rather than requiring programmers to remember to include it in<P>
every initialization <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> that also specifies <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A>.<P>
<P>
<B>Examples:<P>
</B><P>
(<A REL=DEFINITION HREF="../Body/m_defcla.htm#defclass"><B>defclass</B></A> test ()<P>
((slot :initarg :slot-filler))<P>
)<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defmet.htm#defmethod"><B>defmethod</B></A> <A REL=DEFINITION HREF="../Body/f_init_i.htm#initialize-instance"><B>initialize-instance</B></A> :after ((x test) <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;key</B></A>) <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>nil</B></A>)<P>
(<A REL=DEFINITION HREF="../Body/f_mk_ins.htm#make-instance"><B>make-instance</B></A> 'test :slot-filler 5)<P>
-&gt; currently might signal an error<P>
-&gt; returns instance of test under proposed change.<P>
<P>
<B>Current Practice:<P>
</B><P>
Both Lucid 4.0 and IIM 3.4 specify only <A REL=DEFINITION HREF="../Body/03_da.htm#AMrest"><B>&amp;REST</B></A> in the lambda-lists of the<P>
listed generic functions and the specified methods for those functions, with<P>
the implication that user defined methods which specify <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> must also specify<P>
<A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in order to inhibit keyword argument checking by the generic<P>
function from signaling an error due to the presence of &quot;slot filling&quot;<P>
initargs. However, because generic function keyword checking has not yet been<P>
implemented in either Lucid 4.0 or IIM 3.4, users may not be aware of this<P>
requirement. In fact, in IIM 3.4 there are system-supplied initialization<P>
methods that fail to meet this requirement, so there are some implementors who<P>
aren't aware of this problem either.<P>
<P>
Franz Allegro 4.0 appears to have the same behavior as described above for<P>
Lucid 4.0 and IIM 3.4. In particular, generic function keyword checking has<P>
not yet been implemented.<P>
<P>
Symbolics CLOS and Chestnut's Lisp-to-C translator both specify <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> and<P>
<A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in the lambda-lists of the listed generic functions. In<P>
addition, if an applicable <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> for one of the protocols specifies<P>
<A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> then the specified initarg checking for the protocol is not<P>
performed.<P>
<P>
Macintosh Common Lisp 2.0b3c4 has &quot;&amp;KEY &amp;ALLOW-OTHER-KEYS&quot; in the <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> list<P>
for <A REL=DEFINITION HREF="../Body/f_mk_ins.htm#make-instance"><B>MAKE-INSTANCE</B></A>, but all the others just use &quot;&amp;REST&quot;. This asymmetry is an<P>
oversight due to the fact that the <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> combination code special cases them,<P>
and elides normal generic function keyword checking for all of them (hence it<P>
has never appeared as a &quot;bug&quot;). MCL (like Symbolics and Chestnut) also<P>
provides the additional behavior that if one of the applicable methods<P>
specifies <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> then the initarg checking for the protocol is not<P>
performed.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Some possibly tricky code in the implementation may have to be reexamined. In<P>
some implementations it looks like this may involve simply ripping out some<P>
special cases.<P>
<P>
<B>Cost to Users:<P>
</B><P>
Probably none in most cases. Since none of the implementations surveyed ever<P>
signal an error for the described problem case, it is unlikely that any user<P>
code exists which depends on an error being signaled.<P>
<P>
Users can eliminate unnecessary <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> from initialization methods<P>
at their leisure, since its presence or absence has no effect.<P>
<P>
However, those users who have made use of the fairly common but non-portable<P>
meaning of <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in applicable methods as a means of suppressing<P>
initarg validation would have to find some other mechanism for this purpose.<P>
One possibility would be to define appropriate :AROUND or primary methods on<P>
<A REL=DEFINITION HREF="../Body/f_mk_ins.htm#make-instance"><B>MAKE-INSTANCE</B></A> that add :ALLOW-OTHER-KEYS T to the initialization arguments.<P>
<P>
<B>Performance Impact:<P>
</B><P>
None.<P>
<P>
<B>Benefits:<P>
</B><P>
Users and implementors will know what <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in an initialization<P>
<A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A>'s lambda-list means. Programmers writing initialization methods that<P>
specify keywords won't have to remember to include <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A><P>
explicitly. <P>
<P>
<B>Aesthetics:<P>
</B><P>
Requiring all initialization methods that specify <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> to also specify<P>
<A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> is clearly unaesthetic, so this change is an improvement.<P>
<P>
<B>Discussion:<P>
</B><P>
Interestingly, for one reason or another, none of the implementations surveyed<P>
perform generic function keyword checking (as opposed to initarg checking) for<P>
the functions affected by this proposal.<P>
<P>
The possibility of having <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in the lambda-list of an<P>
applicable initialization <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> mean that initarg validation should be<P>
inhibited was discussed, especially in light of the fact that several of the<P>
implementations surveyed already <A REL=DEFINITION HREF="../Body/f_provid.htm#provide"><B>provide</B></A> this behavior. However, some people<P>
questioned whether this was really such a good idea, being unmodular and<P>
perhaps *too* convenient. Also, making such a change would add a real cost to<P>
users who weren't expecting this extension, since they would have to examine<P>
occurances of <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> in initialization methods to decide whether<P>
they were left over from the time when it was (at least theoretically) needed<P>
to inhibit generic function keyword checking or actually there to do the new<P>
thing.<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>