193 lines
13 KiB
HTML
193 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 FUNCTION-TYPE-ARGUMENT-TYPE-SEMANTICS 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/iss174_w.htm">
|
||
|
<LINK REL=UP HREF="../Issues/iss176.htm">
|
||
|
<LINK REL=NEXT HREF="../Issues/iss177_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/iss174_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss176.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss177_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
||
|
|
||
|
<HR>
|
||
|
|
||
|
|
||
|
|
||
|
<H2>Issue FUNCTION-TYPE-ARGUMENT-TYPE-SEMANTICS Writeup</H2>
|
||
|
|
||
|
<PRE><B>Forum:</B> Cleanup<P>
|
||
|
<B>Issue:</B> <A HREF="iss176.htm">FUNCTION-TYPE-ARGUMENT-TYPE-SEMANTICS</A><P>
|
||
|
<B>References:</B> CLtL pp 47-48, 158-159<P>
|
||
|
<B>Category:</B> CHANGE<P>
|
||
|
Related-issues: <A HREF="iss096.htm">DECLARE-TYPE-FREE</A><P>
|
||
|
<B>Edit history:</B> #1, 7 Sept 1988, Walter van Roggen<P>
|
||
|
#2, 13 Sept 1988, Walter van Roggen (costs & proposal limitations)<P>
|
||
|
#3, 7-Dec-88, Masinter<P>
|
||
|
<P>
|
||
|
<P>
|
||
|
<B>Problem description:<P>
|
||
|
</B><P>
|
||
|
The current description of the specialized <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifier is not very<P>
|
||
|
useful to program analysis tools and is not very intuitive to programmers<P>
|
||
|
because the meaning of the argument type specifiers is not restrictive.<P>
|
||
|
<P>
|
||
|
Programmers find it useful to add information about the types of the arguments<P>
|
||
|
a function expects and about the type(s) that a function may return. This<P>
|
||
|
information is useful both to human readers of the code as well as to type<P>
|
||
|
checking programs such as compilers and cross referencers. The only apparent<P>
|
||
|
way of providing this information is with the <A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>FTYPE</B></A> declaration<P>
|
||
|
or the <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifier.<P>
|
||
|
<P>
|
||
|
Furthermore, implementations may wish to <A REL=DEFINITION HREF="../Body/f_provid.htm#provide"><B>provide</B></A> additional optimizations based<P>
|
||
|
on avoiding type checking or different methods of argument passing. These<P>
|
||
|
optimizations <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A> the same sort of information about the argument types.<P>
|
||
|
<P>
|
||
|
However, the current definition of <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifiers on pages 47-48 of<P>
|
||
|
CLtL states that a function such as <A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A> that is of type<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> (T T) <A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A>)<P>
|
||
|
is also of type<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> (<A REL=DEFINITION HREF="../Body/a_float.htm#float"><B>FLOAT</B></A> <A REL=DEFINITION HREF="../Body/a_string.htm#string"><B>STRING</B></A>) <A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A>).<P>
|
||
|
<P>
|
||
|
The problem is that the argument types aren't restrictive, so no interesting<P>
|
||
|
matching of types is possible.<P>
|
||
|
<P>
|
||
|
Proposal (<A HREF="iss176.htm">FUNCTION-TYPE-ARGUMENT-TYPE-SEMANTICS:RESTRICTIVE</A>)<P>
|
||
|
<P>
|
||
|
This proposal is written as if <A HREF="iss096.htm">DECLARE-TYPE-FREE</A> (Version 6, 06-Oct-88)<P>
|
||
|
is in effect.<P>
|
||
|
<P>
|
||
|
Specify that a declaration of the form<P>
|
||
|
<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>ftype</B></A> (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>function</B></A> (arg0-type arg1-type ...) val-type) f))<P>
|
||
|
<P>
|
||
|
implies that any call of the form (f arg0 arg1 ...) within the scope of<P>
|
||
|
the declaration can be treated as if it were<P>
|
||
|
<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>the</B></A> val-type (f (<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>the</B></A> arg0-type arg0) (<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>the</B></A> arg1-type arg1) ...))<P>
|
||
|
<P>
|
||
|
That is, it is an error for any of the arguments not to be of the specified<P>
|
||
|
types or the result not to be of the specified type. (In particular,<P>
|
||
|
If any argument is not of the correct type, the result is not guaranteed <P>
|
||
|
to be of the specified type.)<P>
|
||
|
<P>
|
||
|
Thus, an <A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>FTYPE</B></A> declaration for a function describes calls to the function,<P>
|
||
|
not the actual definition of the function. <P>
|
||
|
<P>
|
||
|
Similarly, specify that a declaration of the form<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>type</B></A> (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>function</B></A> (arg0-type arg1-type ...) val-type) fn-valued-variable)<P>
|
||
|
<P>
|
||
|
has the interpretation that, within the scope of the declaration, it<P>
|
||
|
is an error to call the value of fn-valued-variable with arguments<P>
|
||
|
not of the specified type; assert that the value resulting from a valid<P>
|
||
|
call will be of type val-type.<P>
|
||
|
<P>
|
||
|
As with variable type declarations (cf <A HREF="iss096.htm">DECLARE-TYPE-FREE</A>), nested declarations<P>
|
||
|
imply intersections of types, as follows:<P>
|
||
|
<P>
|
||
|
If two (or more) declarations of the form "ftype" are in effect,<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>ftype</B></A> (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>function</B></A> (arg0-type1 arg1-type1 ...) val-type1) f))<P>
|
||
|
and<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>ftype</B></A> (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>function</B></A> (arg0-type2 arg1-type2 ...) val-type2) f))<P>
|
||
|
<P>
|
||
|
then within the shared scope of the declarations, calls to f can be<P>
|
||
|
treated as if it were declared<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>ftype</B></A> (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>function</B></A> ((<A REL=DEFINITION HREF="../Body/a_and.htm#and"><B>and</B></A> arg0-type1 arg0-type2) (<A REL=DEFINITION HREF="../Body/a_and.htm#and"><B>and</B></A> arg1-type1 arg1-type2 ...) ...)<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/a_and.htm#and"><B>and</B></A> val-type1 val-type2)) <P>
|
||
|
f))<P>
|
||
|
<P>
|
||
|
(It is legitimate to <A REL=DEFINITION HREF="../Body/d_ignore.htm#ignore"><B>ignore</B></A> one <A REL=DEFINITION HREF="../Body/a_or.htm#or"><B>or</B></A> all of <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>the</B></A> declarations in force.)<P>
|
||
|
<P>
|
||
|
<P>
|
||
|
If two (or more) type declarations are in effect for a variable, and<P>
|
||
|
they are both <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> declarations, the declarations combine similarly.<P>
|
||
|
<P>
|
||
|
This proposal does not alter the status (or lack thereof) of other issues<P>
|
||
|
related to <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifiers: what lambda-list keywords mean, what the<P>
|
||
|
<A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>VALUES</B></A> type means, what implications there are w.r.t. argument counts, doing<P>
|
||
|
multiple PROCLAIMs, doing local DECLAREs that shadow other declarations or<P>
|
||
|
proclamations, describing generic functions incrementally, the result of <A REL=DEFINITION HREF="../Body/f_typep.htm#typep"><B>TYPEP</B></A><P>
|
||
|
with a specialized <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type, or the nesting and scoping rules for <P>
|
||
|
<A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>FTYPE</B></A> declarations.<P>
|
||
|
<P>
|
||
|
<B>Example:<P>
|
||
|
</B><P>
|
||
|
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> FFF (F)<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>TYPE</B></A> (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> (<A REL=DEFINITION HREF="../Body/a_float.htm#float"><B>FLOAT</B></A> <A REL=DEFINITION HREF="../Body/a_string.htm#string"><B>STRING</B></A>) <A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A>) F))<P>
|
||
|
... (<A REL=DEFINITION HREF="../Body/f_funcal.htm#funcall"><B>FUNCALL</B></A> F (FOO ...) ...) ... )<P>
|
||
|
<P>
|
||
|
then #'<A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A> is a valid argument to be passed to FFF because the declared<P>
|
||
|
type of the argument is consistent with type (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> (T T) <A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A>).<P>
|
||
|
Within FFF, the declaration permits us, for example, to assume that FOO<P>
|
||
|
returns a <A REL=DEFINITION HREF="../Body/a_float.htm#float"><B>FLOAT</B></A>. <P>
|
||
|
<P>
|
||
|
<B>Rationale:<P>
|
||
|
</B><P>
|
||
|
The proposal seems most like what users expect.<P>
|
||
|
<P>
|
||
|
<B>Current Practice:<P>
|
||
|
</B><P>
|
||
|
VAX LISP assumes and makes use of the semantics different than CLtL<P>
|
||
|
but not exactly what is specified here. Lucid<P>
|
||
|
has a RESTRICTIVE-FTYPE declaration with these semantics and ignores the<P>
|
||
|
<A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> <A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>FTYPE</B></A> declaration. Gold Hill intends to use these declarations in this<P>
|
||
|
manner. Many implementations don't make use of these declarations. At least<P>
|
||
|
several users make use of declarations assuming the new semantics.<P>
|
||
|
<P>
|
||
|
<B>Cost to Implementors:<P>
|
||
|
</B><P>
|
||
|
Since most implementations don't make use of function declarations, and since<P>
|
||
|
those known to do so can be changed easily, the cost should be minimal.<P>
|
||
|
<P>
|
||
|
<B>Cost to Users:<P>
|
||
|
</B><P>
|
||
|
There may be some existing "imprecise" function declarations. However, the<P>
|
||
|
natural tendency when providing these declarations is to be as "descriptive"<P>
|
||
|
(i.e., restrictive but complete) as possible, both for documentation purposes<P>
|
||
|
as well as for potential compiler benefits. There cannot have been any uses of<P>
|
||
|
the specialized <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type for discrimination. Thus most existing uses are<P>
|
||
|
probably compatible with this new definition.<P>
|
||
|
<P>
|
||
|
<B>Cost of Non-Adoption:<P>
|
||
|
</B><P>
|
||
|
There already exists user code on many implementations that assume the<P>
|
||
|
proposed semantics. Not adopting this proposal would continue to render<P>
|
||
|
such code incorrect or at least non-portable.<P>
|
||
|
<P>
|
||
|
<B>Benefits:<P>
|
||
|
</B><P>
|
||
|
Better type checking and more compiler optimizations should be possible.<P>
|
||
|
<P>
|
||
|
<B>Esthetics:<P>
|
||
|
</B><P>
|
||
|
This is the what most programmers expect the specialized <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type to<P>
|
||
|
mean, particularly those coming from other languages.<P>
|
||
|
<P>
|
||
|
<B>Discussion:<P>
|
||
|
</B><P>
|
||
|
A declaration of<P>
|
||
|
(<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> (<A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A>) <A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A>)<P>
|
||
|
is a not proper global declaration for <A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A> if any program might<P>
|
||
|
call <A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A> with arguments that are not <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A>.<P>
|
||
|
<P>
|
||
|
The list form of the <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type specifier is different from most<P>
|
||
|
type specifiers because it cannot be used for discrimination.<P>
|
||
|
Thus, the notion of "subtype" does not make sense, since assertions<P>
|
||
|
about the functional value of a variable are only partially<P>
|
||
|
about the actual value of the variable and mainly about the<P>
|
||
|
values that might be passed to the variables (function) value.<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>
|