emacs.d/clones/lisp/HyperSpec-7-0/HyperSpec/Issues/iss177_w.htm
2023-01-18 20:30:47 +01:00

125 lines
8.3 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 FUNCTION-TYPE-KEY-NAME 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/iss176_w.htm">
<LINK REL=UP HREF="../Issues/iss177.htm">
<LINK REL=NEXT HREF="../Issues/iss178_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/iss176_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss177.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss178_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue FUNCTION-TYPE-KEY-NAME Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss177.htm">FUNCTION-TYPE-KEY-NAME</A><P>
<B>References:</B> CLtL p.47-48, 61<P>
<B>Category:</B> CLARIFICATION, CHANGE<P>
<B>Edit history:</B> Version 1, 23-Nov-1987 Sandra Loosemore<P>
Version 2, 15-Jan-1988 Sandra Loosemore <P>
(from comments by Kent Pitman)<P>
Version 3, 13-Feb-88 Masinter<P>
Related issues: <A HREF="iss178.htm">FUNCTION-TYPE-REST-LIST-ELEMENT</A>, <P>
<A HREF="iss208.htm">KEYWORD-ARGUMENT-NAME-PACKAGE</A><P>
FUNCTION-ARGUMENT-TYPE-SEMANTICS<P>
<P>
<P>
<B>Problem description:<P>
</B><P>
The <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifier list is provided to allow declaration of function<P>
argument types and return value types. This type specifier uses a syntax<P>
similar to the usual <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> list syntax to specify which types go with which<P>
<A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> list variables. However, there is a problem with <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> variables<P>
because CLtL does not specify how the types specified in the <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A><P>
declaration are matched up to either the actual arguments passed to the<P>
function, or the <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> variables in the function definition (since the ordering<P>
of keyword arguments is arbitrary).<P>
<P>
<B>Proposal (FUNCTION-TYPE-KEY-NAME:SPECIFY-KEYWORD):<P>
</B><P>
(1) Specify that the <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> parameters in a <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifier <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> list<P>
should be supplied as lists of the form (&lt;keyword&gt; &lt;type&gt;). The &lt;keyword&gt; must<P>
be a valid keyword-name symbol as must be supplied in the actual arguments of a<P>
call. (This is usually a symbol in the keyword package, but, as per<P>
<A HREF="iss208.htm">KEYWORD-ARGUMENT-NAME-PACKAGE</A>, not necessarily so.) <P>
<P>
(2) Allow <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> to appear in a <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifier <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> list. <P>
<P>
The interpretation of such declarations is that, when <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> is given in a<P>
<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifier <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> list, it is safe to assume that the &amp;KEYs given<P>
are exhaustive unless <A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> is present. <P>
<P>
<A REL=DEFINITION HREF="../Body/03_da.htm#AMallow-other-keys"><B>&amp;ALLOW-OTHER-KEYS</B></A> is an indication that other keyword arguments may actually be<P>
supplied and, if supplied, may be used. <P>
<P>
<B>Example:<P>
</B><P>
The type of the function <A REL=DEFINITION HREF="../Body/f_mk_lis.htm#make-list"><B>MAKE-LIST</B></A> could be declared as:<P>
<P>
(<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> <A REL=DEFINITION HREF="../Body/f_mk_lis.htm#make-list"><B>MAKE-LIST</B></A> ((<A REL=DEFINITION HREF="../Body/t_intege.htm#integer"><B>INTEGER</B></A> 0) <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> (:INITIAL-ELEMENT T)) <A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A>)<P>
<P>
<B>Rationale:<P>
</B><P>
(1) This specifies a direct correspondence between the argument type and its<P>
matching keyword. All of the information is in one place, and the user does not<P>
have to remember (or even know) the order in which <A REL=DEFINITION HREF="../Body/03_da.htm#AMkey"><B>&amp;KEY</B></A> arguments appear in the<P>
actual function definition.<P>
<P>
(2) This is probably an oversight in the original specification.<P>
<P>
<B>Current practice:<P>
</B><P>
Many Common Lisp implementations currently ignore <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type declarations.<P>
The situation regarding type specifications for keyword arguments is so<P>
ambiguous that few users attempt to use them.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Implementations that ignore the <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifier or keyword arguments in<P>
a <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifier may continue to do so. This proposal should not<P>
involve massive amounts of code to be rewritten.<P>
<P>
<B>Cost to users:<P>
</B><P>
Because the current situation is so ambiguous, <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifiers and<P>
particularly the specification of keyword argument types are not widely used.<P>
However, since this is an incompatible change, it would be nice if<P>
implementations check for, and warn about, old-style usage.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
If nothing is done, the <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifier will continue to be of limited<P>
use for its intended purpose.<P>
<P>
<B>Benefits:<P>
</B><P>
Adopting the proposal will clear up an area of confusion in the language design.<P>
<P>
<B>Esthetics:<P>
</B><P>
The syntax is fairly obvious and is analogous to the (&lt;keyword&gt; &lt;variable&gt;)<P>
<A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A> list syntax.<P>
<P>
<B>Discussion:<P>
</B><P>
The exact semantics of function declarations and the types of arguments is<P>
still under discussion, as are several other issues dealing with declarations.<P>
However, this issue seemed separable.<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>