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

143 lines
9.2 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 DECLARE-FUNCTION-AMBIGUITY 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/iss093_w.htm">
<LINK REL=UP HREF="../Issues/iss094.htm">
<LINK REL=NEXT HREF="../Issues/iss095_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/iss093_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss094.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss095_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue DECLARE-FUNCTION-AMBIGUITY Writeup</H2>
<PRE><B>Forum:</B> Cleanup<P>
<B>Issue:</B> <A HREF="iss094.htm">DECLARE-FUNCTION-AMBIGUITY</A><P>
<P>
<B>References:</B> CLtL pp 43 (Table 4-1), 158-159<P>
Issue <A HREF="iss175_m.htm">FUNCTION-TYPE</A> (passed X3J13/June 1988)<P>
<P>
<B>Category:</B> CHANGE<P>
<P>
<B>Edit history:</B> #1, 21 Sept 1988, Walter van Roggen<P>
#2, 29 Sept 1988, Walter van Roggen (renamed; lessened ambiguity)<P>
#3, 30-Sep-88, Masinter<P>
#4, 5-Dec-88, Masinter (append Oct x3j13 comments)<P>
<P>
<B>Problem description:<P>
</B><P>
CLtL permits confusing and ambiguous <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> declarations. One can say<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> F (<A REL=DEFINITION HREF="../Body/a_vector.htm#vector"><B>VECTOR</B></A> <A REL=DEFINITION HREF="../Body/t_intege.htm#integer"><B>INTEGER</B></A>) T))<P>
to indicate that the function binding for F is of a certain type. Yet<P>
one can also say<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> X Y Z))<P>
to indicate that the variables X, Y, and Z have values which are functions.<P>
<P>
The former is an abbreviation for<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<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_vector.htm#vector"><B>VECTOR</B></A> <A REL=DEFINITION HREF="../Body/t_intege.htm#integer"><B>INTEGER</B></A>) T) F))<P>
The latter is an abbreviation for<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> X Y Z))<P>
<P>
The ambiguity arises in a case like<P>
(<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> F <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> <A REL=DEFINITION HREF="../Body/a_string.htm#string"><B>STRING</B></A>))<P>
However, it would be an error to declare the type of the constant <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> to be a<P>
<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A>, so technically there is no ambiguity--there is just a peculiar<P>
special case.<P>
<P>
Using the same declaration for two completely different purposes can lead<P>
to confusion among people writing or reading such code.<P>
<P>
It is now more useful to declare that variables have a value which<P>
is of type <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A>, since the type <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> has a more well-specified<P>
meaning.<P>
<P>
Proposal (<A HREF="iss094.htm">DECLARE-FUNCTION-AMBIGUITY:DELETE-FTYPE-ABBREVIATION</A>)<P>
<P>
The declaration (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> name argtypes valtypes) is no longer permitted<P>
to be an abbreviation for (<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> argtypes valtypes) name).<P>
<P>
The declaration (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> var1 var2) would just be an abbreviation for<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> var1 var2).<P>
<P>
<B>Rationale:<P>
</B><P>
Continuing to allow all the predefined atomic type specifiers as declaration<P>
abbreviations for (<A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>TYPE</B></A> type var1 var2 ...) is simpler for users to understand.<P>
In other words, all the normal type declarations describe variable bindings;<P>
only the <A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>FTYPE</B></A> declaration describes function bindings. This is a more<P>
uniform solution than making an exception to table 4-1.<P>
<P>
Since the old use of the <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> declaration for function bindings was just<P>
an abbreviation for the <A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>FTYPE</B></A> declaration, no expressivity is lost.<P>
Furthermore one is able to say that a variable's value is of type <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A>,<P>
something that hadn't been clearly possible without using the <A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>TYPE</B></A> declaration.<P>
<P>
<B>Current Practice:<P>
</B><P>
Many current implementations treat <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> declarations <P>
only as abbreviations for <A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>FTYPE</B></A> declarations, primarily because<P>
the proposal <A HREF="iss175_m.htm">FUNCTION-TYPE</A> has not been widely implemented.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Likely to be small to those implementations that heed these kinds of<P>
declarations; none for those that don't.<P>
<P>
<B>Cost to Users:<P>
</B><P>
Existing uses of the <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> declaration for function bindings will need<P>
to be changed to <A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>FTYPE</B></A> declarations.<P>
<P>
<B>Cost of Non-Adoption:<P>
</B><P>
People will continue to be confused by function declarations.<P>
<P>
<B>Benefits:<P>
</B><P>
A simpler language.<P>
<P>
<B>Esthetics:<P>
</B><P>
<P>
<B>Discussion:<P>
</B><P>
Making it clear that only <A REL=DEFINITION HREF="../Body/d_ftype.htm#ftype"><B>FTYPE</B></A> declarations describe function bindings will<P>
make it easier to add new kinds of declarations that support incremental or<P>
additional descriptions, as is needed for describing methods.<P>
<P>
Since all cases can be disambiguated after all, compatibility considerations<P>
might deem this proposal to be unnecessary. However, making declarations<P>
simpler and less confusing is possibly more important than compatibility.<P>
<P>
There is no consensus on the cleanup committee.<P>
<P>
Comments from October 1988 X3J13 meeting:<P>
<P>
... opposed but not vehemently--the incompatible change is gratuitous<P>
... prefer to document the<P>
issue rather than change it.&quot;<P>
... a number of implementations accidentally implement<P>
this incorrectly. They first check the type table and then handle<P>
the elaborate function declaration style. But, as it happens,<P>
they never reach the code for the second case because function is<P>
in the type table!<P>
... Having both styles is worse than having either one or the other.<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>