220 lines
13 KiB
HTML
220 lines
13 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 KEYWORD-ARGUMENT-NAME-PACKAGE 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/iss199_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss208.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss209_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/iss199_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss208.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss209_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue KEYWORD-ARGUMENT-NAME-PACKAGE Writeup</H2>
|
|
|
|
<PRE>Version 6 conditionally passed X3J13/Jun87. Version 8 distributed in hardcopy<P>
|
|
form X3J13/Nov87.<P>
|
|
<P>
|
|
!<P>
|
|
<B>Issue:</B> <A HREF="iss208.htm">KEYWORD-ARGUMENT-NAME-PACKAGE</A><P>
|
|
<B>References:</B> Lambda Expressions (CLtL pp60-64)<P>
|
|
<B>Category:</B> CLARIFICATION/CHANGE<P>
|
|
<B>Edit history:</B> 20-Apr-87, Version 1 by Moon<P>
|
|
29-Apr-87, Version 2 by Pitman<P>
|
|
11-May-87, Version 3 by Moon<P>
|
|
29-May-87, Version 4 by Masinter <P>
|
|
5-Jun-87, Version 5 by Masinter<P>
|
|
11-Jun-87, Version 6 by Masinter<P>
|
|
23-Oct-87, Version 7 by Masinter<P>
|
|
8-Nov-87, Version 8 by Moon<P>
|
|
<P>
|
|
<B>Problem Description:<P>
|
|
</B><P>
|
|
CLtL says that only keyword symbols can be used as keyword-names in<P>
|
|
&key parameter specifiers (page 60, "each -keyword- must be a<P>
|
|
keyword symbol, such as :start.")<P>
|
|
<P>
|
|
As Common Lisp is currently defined, if someone wants to define a<P>
|
|
function that accepts keyword (rather than positional) arguments whose<P>
|
|
keyword-names are symbols in packages other than the <A REL=DEFINITION HREF="../Body/t_kwd.htm#keyword"><B>KEYWORD</B></A> package,<P>
|
|
they cannot use <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&KEY</B></A>. Instead, they have to duplicate the <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&KEY</B></A> mechanism<P>
|
|
using <A REL=DEFINITION HREF="../Body/03_da.htm#AMrest"><B>&REST</B></A>, <A REL=DEFINITION HREF="../Body/f_getf.htm#getf"><B>GETF</B></A>, and (if they want error checking of argument names)<P>
|
|
<A REL=DEFINITION HREF="../Body/m_do_do.htm#do"><B>DO</B></A>.<P>
|
|
<P>
|
|
Some applications (including the draft proposal for the Common Lisp<P>
|
|
Object System (CLOS)) <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A> this capability. [See Rationale below.]<P>
|
|
<P>
|
|
Proposal (<A HREF="iss208.htm">KEYWORD-ARGUMENT-NAME-PACKAGE:ANY</A>)<P>
|
|
<P>
|
|
Remove restrictions on the package of the keyword-names of keyword<P>
|
|
parameters; allow any symbol. That is:<P>
|
|
<P>
|
|
If, following an <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&KEY</B></A>, a variable appears alone or in a (variable<P>
|
|
default-value) pair, the behavior specified in CLtL is unchanged: a<P>
|
|
keyword symbol with the same print name as the variable is created and<P>
|
|
is used as the keyword-name when matching arguments to parameter<P>
|
|
specifiers. A keyword-name that is not a keyword symbol can be<P>
|
|
specified with the ((-keyword- -var-) ...) syntax of parameter<P>
|
|
specifier. The -keyword- can be any symbol, not just a keyword.<P>
|
|
<P>
|
|
A future specification of Common Lisp could be written with revised<P>
|
|
terminology that did not use the term "keyword" to refer to three<P>
|
|
different things: symbols in the <A REL=DEFINITION HREF="../Body/t_kwd.htm#keyword"><B>KEYWORD</B></A> package, symbols beginning<P>
|
|
with & that have special meaning in lambda-lists, and keyword-names<P>
|
|
used to match function arguments to keyword parameter specifiers.<P>
|
|
However, this proposal does not propose to change any terminology.<P>
|
|
<P>
|
|
<B>Test case:<P>
|
|
</B><P>
|
|
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> RESULT (<A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&KEY</B></A> ((SECRET-KEYWORD SECRET) <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>) AMOUNT)<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_format.htm#format"><B>FORMAT</B></A> <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> "You ~A $~D" (<A REL=DEFINITION HREF="../Body/s_if.htm#if"><B>if</B></A> SECRET "win" "lose") AMOUNT))<P>
|
|
<P>
|
|
(RESULT :AMOUNT 100) => "You lose $100"<P>
|
|
(RESULT :AMOUNT 100 'SECRET-KEYWORD T) => "You win $100"<P>
|
|
<P>
|
|
<P>
|
|
<B>Rationale:<P>
|
|
</B><P>
|
|
The "rationale" box on p.62 of CLtL is an argument in favor of requiring<P>
|
|
keyword-names to be symbols, and disallowing numbers, but does not<P>
|
|
speak to the issue of whether or not those symbols should be further<P>
|
|
restricted to be in the <A REL=DEFINITION HREF="../Body/t_kwd.htm#keyword"><B>KEYWORD</B></A> package.<P>
|
|
<P>
|
|
The desire for keyword parameters whose keyword-names are not in the<P>
|
|
<A REL=DEFINITION HREF="../Body/t_kwd.htm#keyword"><B>KEYWORD</B></A> package arises when the set of keyword-names accepted by a<P>
|
|
function is the union of the sets of keyword-names accepted by several<P>
|
|
other functions, rather than being enumerated in a single place. In<P>
|
|
this case, it becomes desirable to use packages to prevent accidental<P>
|
|
name clashes among keyword-names of different functions.<P>
|
|
<P>
|
|
One example of a Common Lisp application that requires this capability<P>
|
|
is the draft proposal for an object-oriented programming <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A><P>
|
|
(CLOS). It will have generic functions that accept arguments and pass<P>
|
|
them on to one or more applicable methods, with each <A REL=DEFINITION HREF="../Body/t_method.htm#method"><B>method</B></A> defining its<P>
|
|
own set of keyword-names that it is interested in. If this proposal is<P>
|
|
not adopted, either the keyword-names will be required to be keywords,<P>
|
|
which will <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A> the methods to have non-modular knowledge of each<P>
|
|
other in order to avoid name clashes, or the methods will have to be<P>
|
|
defined with an ad hoc mechanism that duplicates the essential<P>
|
|
functionality of &key but removes the restriction.<P>
|
|
<P>
|
|
A second example of a Common Lisp application that requires this<P>
|
|
capability is private communication channels between functions. Suppose<P>
|
|
a public routine MAKE-FOO needs to accept arbitrary arguments from the<P>
|
|
caller and passes those arguments along to an internal routine with<P>
|
|
additional arguments of its own, and suppose that keyword parameters<P>
|
|
are used to receive these arguments.<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_in_pkg.htm#in-package"><B>IN-PACKAGE</B></A> 'FOOLAND)<P>
|
|
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> MAKE-FOO (<A REL=DEFINITION HREF="../Body/03_da.htm#AMrest"><B>&REST</B></A> NAME-VALUE-PAIRS <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&KEY</B></A> <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&ALLOW-OTHER-KEYS</B></A>)<P>
|
|
(<A REL=DEFINITION HREF="../Body/f_apply.htm#apply"><B>APPLY</B></A> #'MAKE-FOO-INTERNAL 'EXPLICIT T NAME-VALUE-PAIRS))<P>
|
|
<P>
|
|
This could be done without fear that the use of EXPLICIT T would<P>
|
|
override some argument in NAME-VALUE-PAIRS, since the only way<P>
|
|
that could happen is if someone had done (MAKE-FOO 'FOOLAND::EXPLICIT<P>
|
|
<A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>), or if the user was programming explicitly in the FOOLAND package,<P>
|
|
either of which is an implicit admission of willingness to violate<P>
|
|
FOOLAND's modularity.<P>
|
|
<P>
|
|
<B>Documentation Impact:<P>
|
|
</B><P>
|
|
Some careful rewording of the existing language in CLtL is necessary in<P>
|
|
the <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> to avoid confusion between "keyword", indicating a symbol<P>
|
|
in the <A REL=DEFINITION HREF="../Body/t_kwd.htm#keyword"><B>KEYWORD</B></A> package, and "keyword name", indicating a syntactic part<P>
|
|
of a keyword parameter specifier. It is likely that this is best served<P>
|
|
by changing those instances of "keyword" to "named argument" when the<P>
|
|
specification is discussing the indicator which introduces an actual<P>
|
|
parameter in a call to a function defined with <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&KEY</B></A>.<P>
|
|
<P>
|
|
The wording which refers to named arguments as being introduced by<P>
|
|
keyword symbols would change to simply refer to those arguments being<P>
|
|
introduced by symbols. For example, in the middle of p.60, the sentence:<P>
|
|
... each -keyword- must be a keyword symbol, such as :start.<P>
|
|
would become<P>
|
|
... each named argument name must be a symbol.<P>
|
|
<P>
|
|
The word "keyword" in the first complete sentence on p.62 would be<P>
|
|
changed to "symbol" for similar reasons.<P>
|
|
<P>
|
|
Extra wording would have to be added on p.60 to explain that by<P>
|
|
convention keyword symbols are normally used as the names for named<P>
|
|
arguments, and that all functions built into the Common Lisp language<P>
|
|
follow that convention.<P>
|
|
<P>
|
|
<B>Examples would be useful. On p.64 the following examples might be added:<P>
|
|
</B><P>
|
|
((<A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> (a b <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&key</B></A> ((:sea c)) d) (<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>list</B></A> a b c d)) 1 2 :sea 6)<P>
|
|
=> (1 2 6 <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>)<P>
|
|
<P>
|
|
((<A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> (a b <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&key</B></A> ((c c)) d) (<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>list</B></A> a b c d)) 1 2 'c 6)<P>
|
|
=> (1 2 6 <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A>)<P>
|
|
<P>
|
|
<B>Current Practice:<P>
|
|
</B><P>
|
|
We do not currently know of an implementation that enforces the<P>
|
|
restriction that this proposal seeks to remove.<P>
|
|
<P>
|
|
Some implementations have bugs that prevent <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> from working as a<P>
|
|
keyword argument name, but allow all non-NIL symbols. (One Symbolics<P>
|
|
version that was checked had this bug.)<P>
|
|
<P>
|
|
<B>Cost to implementors:<P>
|
|
</B><P>
|
|
Some implementors might have to rearrange their error checking slightly,<P>
|
|
but it should be very easy.<P>
|
|
<P>
|
|
<B>Cost to users:<P>
|
|
</B><P>
|
|
None--no existing programs will stop working. <P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
This will help with the object-oriented programming <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A>, among<P>
|
|
other things.<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
The restriction of &key to only keyword symbols is arbitrary and<P>
|
|
unnecessary.<P>
|
|
<P>
|
|
There will probably be an argument about whether the restriction is more<P>
|
|
aesthetic or less aesthetic than the freedom, but in either case the<P>
|
|
aesthetic effect is slight.<P>
|
|
<P>
|
|
In any case, users who do not want to use the extended functionality can<P>
|
|
generally avoid it.<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
The cleanup committee generally supports this extension. <P>
|
|
<P>
|
|
Moon was under the impression that this proposal was actually adopted<P>
|
|
around December 1985 (although no formal mechanism for adopting<P>
|
|
proposals existed at that time), but may be mistaken.<P>
|
|
<P>
|
|
If Common Lisp truly has a restriction that only keyword symbols can be<P>
|
|
used as keyword names in calls to functions that take keyword arguments,<P>
|
|
it will be more difficult to come up with an object-oriented programming<P>
|
|
<A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> that fits within Common Lisp.<P>
|
|
<P>
|
|
The cleanup committee considered, but did not adopt, a proposal to<P>
|
|
exclude <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> as a legal indicator. It might catch some errors, but is<P>
|
|
otherwise an odd restriction.<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>
|