163 lines
10 KiB
HTML
163 lines
10 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 THE-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/iss345_w.htm">
|
|
<LINK REL=UP HREF="../Issues/iss346.htm">
|
|
<LINK REL=NEXT HREF="../Issues/iss347_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/iss345_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss346.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss347_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
|
|
|
|
<H2>Issue THE-AMBIGUITY Writeup</H2>
|
|
|
|
<PRE><B>Forum:</B> cleanup<P>
|
|
<B>Issue:</B> <A HREF="iss346.htm">THE-AMBIGUITY</A><P>
|
|
<B>References:</B> <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> (page 161)<P>
|
|
<B>Category:</B> CLARIFICATION<P>
|
|
<B>Edit history:</B> 21-Oct-88, version 1 by Rees<P>
|
|
11-Jan-89, version 2 by Masinter (fix typos)<P>
|
|
<P>
|
|
<B>Problem description:<P>
|
|
</B><P>
|
|
CLtL does not explicitly say whether the type specifier in a <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A><P>
|
|
form may be any type specifier or must be a type specifier suitable<P>
|
|
for discrimination. Although <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> is decsribed as a "declaration"<P>
|
|
form, some CL implementations have assumed that the specifier must<P>
|
|
be for discrimination, and disallow e.g.,<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> (<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>) #'<A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A>)<P>
|
|
<P>
|
|
We should either say that the implementations are right, or<P>
|
|
explicitly say that they are wrong, since this case is easily<P>
|
|
overlooked.<P>
|
|
<P>
|
|
<B>Proposal (THE-AMBIGUITY:FOR-DECLARATION):<P>
|
|
</B><P>
|
|
Clarify that the type specifier in<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> type exp)<P>
|
|
<P>
|
|
may be any valid type specifier. In the case that exp returns one<P>
|
|
value and type is not a <A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>VALUES</B></A> type specifier, (<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> type exp) is<P>
|
|
equivalent to<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_let_l.htm#let"><B>LET</B></A> ((g exp))<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> type g))<P>
|
|
g)<P>
|
|
<P>
|
|
where "g" is a <A REL=DEFINITION HREF="../Body/f_gensym.htm#gensym"><B>gensym</B></A>.<P>
|
|
<P>
|
|
<B>Proposal (THE-AMBIGUITY:FOR-DISCRIMINATION):<P>
|
|
</B><P>
|
|
Clarify that the type specifier in<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> type exp)<P>
|
|
<P>
|
|
must be a valid type for discrimination, as for <A REL=DEFINITION HREF="../Body/f_typep.htm#typep"><B>TYPEP</B></A>, or it must<P>
|
|
be of the form (<A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>VALUES</B></A> type*) where type* are all valid for discrimination.<P>
|
|
<P>
|
|
<B>Current practice:<P>
|
|
</B><P>
|
|
The Symbolics Genera and VAX LISP V2.2 interpreters signal errors for<P>
|
|
<P>
|
|
(<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> (<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>) #'<A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A>),<P>
|
|
<P>
|
|
but this may not be intentional. CLtL would seem to allow it.<P>
|
|
<P>
|
|
<B>Test case:<P>
|
|
</B><P>
|
|
(<A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> (<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>) #'<A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A>),<P>
|
|
<P>
|
|
should return the <A REL=DEFINITION HREF="../Body/a_cons.htm#cons"><B>CONS</B></A> function under FOR-DECLARATION,<P>
|
|
and should be an error under FOR-DISCRIMINATION.<P>
|
|
<P>
|
|
<B>Cost to implementors:<P>
|
|
</B><P>
|
|
Trivial cost for THE-AMBIGUITY:FOR-DISCRIMINATION; this is a compatible<P>
|
|
restriction.<P>
|
|
<P>
|
|
For <A HREF="iss346.htm">THE-AMBIGUITY:FOR-DECLARATION</A>, implementations that do not<P>
|
|
already allow arbitrary type specifiers but which want to check that<P>
|
|
the type in a <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> is satisfied would have to create an internal<P>
|
|
version of <A REL=DEFINITION HREF="../Body/f_typep.htm#typep"><B>TYPEP</B></A> which could manage not to signal invalid-type-specifier<P>
|
|
errors in those situations where <A REL=DEFINITION HREF="../Body/f_typep.htm#typep"><B>TYPEP</B></A> would because the type is a<P>
|
|
declaration-only one.<P>
|
|
<P>
|
|
<B>Cost to users:<P>
|
|
</B><P>
|
|
Users of implementations that support <A HREF="iss346.htm">THE-AMBIGUITY:FOR-DECLARATION</A><P>
|
|
might have to remove or change some uses of <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> in their code if the<P>
|
|
opposing alternative is adopted.<P>
|
|
<P>
|
|
<B>Benefits:<P>
|
|
</B><P>
|
|
Either way, an ambiguity in the language specification would be clarified.<P>
|
|
<P>
|
|
<B>Aesthetics:<P>
|
|
</B><P>
|
|
<A HREF="iss346.htm">THE-AMBIGUITY:FOR-DECLARATION</A> would seem to be more consistent with<P>
|
|
<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> and with the intent of <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A>, which is supposed to be a way to<P>
|
|
<A REL=DEFINITION HREF="../Body/f_provid.htm#provide"><B>provide</B></A> information for documentation and for the benefit of compilation.<P>
|
|
<P>
|
|
<B>Discussion:<P>
|
|
</B><P>
|
|
Rees supports <A HREF="iss346.htm">THE-AMBIGUITY:FOR-DECLARATION</A>.<P>
|
|
<P>
|
|
Appropriate error situation terminology must be chosen for the<P>
|
|
situation that a <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> declaration (or other declaration) is<P>
|
|
unsatisfied, but that must be done regardless of this proposal.<P>
|
|
<P>
|
|
This proposal would suggest that a function should be added to CL to<P>
|
|
do the checking that <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> would want to do:<P>
|
|
<P>
|
|
(PROBABLY-TYPEP object type-spec)<P>
|
|
<P>
|
|
[terrible name of course] returns multiple values a la SUBTYPEP: T T<P>
|
|
if the object definitely has the type, <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> T if it definitely<P>
|
|
doesn't, and T <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> (or <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> NIL?) otherwise. Assuming that an<P>
|
|
interpreted THE-expression actually checks types, you could almost<P>
|
|
define this function using the condition system and <A REL=DEFINITION HREF="../Body/f_eval.htm#eval"><B>EVAL</B></A>. (Ugh!)<P>
|
|
Without PROBABLY-TYPEP, a meta-circular interpreter is more<P>
|
|
difficult to write.<P>
|
|
<P>
|
|
If a suitable name was found for this function, the additional<P>
|
|
functionality could be suggested as an independent proposal, since<P>
|
|
regardless of the outcome of this issue, the functionality is still<P>
|
|
useful for checking <A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A>'s.<P>
|
|
<P>
|
|
Various implementation mechanisms were discussed for dealing<P>
|
|
with <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> checking.<P>
|
|
<P>
|
|
Are there any remaining type specifiers beyond the list form<P>
|
|
of the <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> type that differ between "declaration" and<P>
|
|
"discrimination"?<P>
|
|
<P>
|
|
"I support FOR-DECLARATION. Lucid CL has the same bug in<P>
|
|
the interpreter as the others (a "bug" assuming FOR-DECLARATION).<P>
|
|
<A REL=DEFINITION HREF="../Body/f_typep.htm#typep"><B>TYPEP</B></A> is used to check the legality of the type specifier in <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A>."<P>
|
|
<P>
|
|
In considering possible ways in which the type-checking logic<P>
|
|
for <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> and <A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> might work, don't forget things like<P>
|
|
(the (not (function (t t) integer)) 7),<P>
|
|
which you would want to signal an error. I don't think this can be<P>
|
|
done with only <A REL=DEFINITION HREF="../Body/f_typep.htm#typep"><B>TYPEP</B></A> and conditions.<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>
|