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

138 lines
7.6 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-CONSTRUCTOR-KEY-MIXTURE 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/iss108_w.htm">
<LINK REL=UP HREF="../Issues/iss109.htm">
<LINK REL=NEXT HREF="../Issues/iss110_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/iss108_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss109.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss110_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue DEFSTRUCT-CONSTRUCTOR-KEY-MIXTURE Writeup</H2>
<PRE><B>Forum:</B> Cleanup<P>
<B>Issue:</B> <A HREF="iss109.htm">DEFSTRUCT-CONSTRUCTOR-KEY-MIXTURE</A><P>
<B>References:</B> CLtL page 316<P>
<B>Category:</B> CHANGE<P>
<B>Edit history:</B> 20-Sep-88, Version 1, Peck<P>
21-Sep-88, Version 2, Masinter, minor revisions<P>
8-Jan-89, Version 3, Masinter<P>
<P>
<P>
<B>Problem description:<P>
</B><P>
Currently, <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> constructor functions can be either the default<P>
constructor function, with *only* keyword arguments, or it can be a <P>
so-called &quot;By Order of Arguments&quot; constructor function with explicitly<P>
*no* keyword arguments. Other functions in Common Lisp allow a free<P>
mix of required, optional, and keyword arguments. <P>
<P>
With the current restriction, it is necessary to hand code a function that<P>
will accept optional and keyword arguments and parse the supplied-p<P>
variables explicitly. Even so, it is not obvious to the casual programmer<P>
how to <A REL=DEFINITION HREF="../Body/f_provid.htm#provide"><B>provide</B></A> the same semantics as <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> does with respect to default<P>
values and the <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> init-forms.<P>
<P>
Proposal: <A HREF="iss109.htm">DEFSTRUCT-CONSTRUCTOR-KEY-MIXTURE:ALLOW-KEY</A><P>
<P>
Allow <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> keyword arguments in constructor forms of DEFSTRUCTs<P>
and the <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> token in addition to the <A REL=DEFINITION HREF="../Body/03_da.htm#AMoptional"><B>&amp;OPTIONAL</B></A>,<P>
<A REL=DEFINITION HREF="../Body/03_da.htm#AMrest"><B>&amp;REST</B></A> and <A REL=DEFINITION HREF="../Body/03_da.htm#AMaux"><B>&amp;AUX</B></A> arguments already allowed. Keyword arguments default<P>
in a manner similar to that of <A REL=DEFINITION HREF="../Body/03_da.htm#AMoptional"><B>&amp;OPTIONAL</B></A> arguments: if no default<P>
is supplied in the lambda-list then the slot initform is used;<P>
otherwise the slot is not initialized -- its initial value is<P>
undefined.<P>
<P>
If keyword arguments of the form ((key var) [default [svar]])<P>
are specified, the &quot;slot name&quot; is matched with VAR (and not KEY).<P>
<P>
Additional arguments that do not correspond to slot names but<P>
are merely present to supply values used in subsequent initialization <P>
computations are allowed.<P>
<P>
<P>
<B>Examples:<P>
</B><P>
It should be possible to write forms like this:<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> (foo (:constructor CREATE-FOO (a <A REL=DEFINITION HREF="../Body/03_da.htm#AMoptional"><B>&amp;optional</B></A> b (c 'sea)<P>
<A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;key</B></A> (d 2)<P>
<A REL=DEFINITION HREF="../Body/03_da.htm#AMaux"><B>&amp;aux</B></A> e (f 'eff))))<P>
(a 1) (b 2) (c 3) (d 4) (e 5) (f 6))<P>
<P>
(create-foo 10) =&gt; #S(foo a 10 b 2 c sea d 2 e nil f eff)<P>
(create-foo 10 'bee 'see :d 'dee) =&gt; #S(foo a 10 b bee c see d dee e nil f eff)<P>
<P>
In the definition:<P>
(<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>defstruct</B></A> (frob (:constructor create-frob<P>
(a <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;key</B></A> (b 3 have-b) (c-token 'c) <P>
(c (<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>list</B></A> c-token (<A REL=DEFINITION HREF="../Body/s_if.htm#if"><B>if</B></A> have-b 7 2))))))<P>
a b c)<P>
<P>
the c-token argument is used merely to supply a value used in the <P>
initialization of the c slot. The &quot;supplied-p&quot; arguments of<P>
keyword arguments might be of this form.<P>
<P>
<B>Rationale:<P>
</B><P>
This is a logical extension of the specification which makes some<P>
programming easier.<P>
<P>
<B>Current practice:<P>
</B><P>
Many implementations signal an error if given <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> arguments or<P>
arguments that are not slot names. The latest version of IIM Common <P>
Lisp allows <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> arguments in this manner. Envos Medley<P>
(Xerox Common Lisp) implements the proposal. <P>
<P>
<B>Cost to Implementors:<P>
</B><P>
The modifications to allow intermixed keywords and optionals in implementations<P>
that don't already are likely simple. <P>
<P>
<B>Cost to Users:<P>
</B><P>
No cost, this is upward compatible.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
The current situation is non-intuitive and needless restrictive.<P>
<P>
<B>Benefits:<P>
</B><P>
Much easier for users to write the constructor function they want.<P>
Probably implementation code would be reduced, since this would no <P>
longer be an error.<P>
<P>
<B>Esthetics:<P>
</B><P>
Minor improvement since it removes a needless restriction.<P>
<P>
<B>Discussion:<P>
</B><P>
Possibly references to &quot;By-position&quot;, &quot;positional&quot;, and &quot;By Order of<P>
Arguments&quot; constructor function might need to be changed to something else in<P>
the <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A>. (They can still be called BOA-constructors, though, right? :-)<P>
<P>
Version 2 of this proposal was on the January 1989 ballot.<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>