186 lines
10 KiB
HTML
186 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-VALUES 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/iss346_w.htm">
|
||
|
<LINK REL=UP HREF="../Issues/iss347.htm">
|
||
|
<LINK REL=NEXT HREF="../Issues/iss348_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/iss346_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss347.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss348_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
||
|
|
||
|
<HR>
|
||
|
|
||
|
|
||
|
|
||
|
<H2>Issue THE-VALUES Writeup</H2>
|
||
|
|
||
|
<PRE><B>Issue:</B> <A HREF="iss347.htm">THE-VALUES</A><P>
|
||
|
<B>References:</B> <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> special form, <A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>VALUES</B></A> type specifier<P>
|
||
|
Related issues: <A HREF="iss346.htm">THE-AMBIGUITY</A><P>
|
||
|
<B>Category:</B> CLARIFICATION<P>
|
||
|
<B>Edit history:</B> v1, 24 Feb 1991, Sandra Loosemore<P>
|
||
|
<B>Status:</B> X3J13 passed v1:RETURN-NUMBER-RECEIVED on vote of 10-1, Mar-91<P>
|
||
|
<P>
|
||
|
<B>Problem description:<P>
|
||
|
</B><P>
|
||
|
Are the following forms valid, and if so how many values are returned <P>
|
||
|
in each case?<P>
|
||
|
<P>
|
||
|
#1: (truncate 7 3)<P>
|
||
|
#2: (the integer (truncate 7 3))<P>
|
||
|
#3: (the (values integer) (truncate 7 3))<P>
|
||
|
#4: (the (values integer integer) (truncate 7 3))<P>
|
||
|
#5: (the (values integer integer symbol) (truncate 7 3))<P>
|
||
|
<P>
|
||
|
There are two proposals, RETURN-NUMBER-RECEIVED and STRICT-MATCHING.<P>
|
||
|
<P>
|
||
|
<B>Proposal (THE-VALUES:RETURN-NUMBER-RECEIVED):<P>
|
||
|
</B><P>
|
||
|
(1) Clarify that the <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> special form returns the exact values as <P>
|
||
|
its subform.<P>
|
||
|
<P>
|
||
|
(2) Clarify that it is not an error if the subform returns more values <P>
|
||
|
than what is specified by the type specifier, provided that the<P>
|
||
|
values for which types are declared are indeed of those types.<P>
|
||
|
(In particular, <A REL=DEFINITION HREF="../Body/s_if.htm#if"><B>if</B></A> <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>the</B></A> <A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>type</B></A> specifier is <A REL=DEFINITION HREF="../Body/a_not.htm#not"><B>not</B></A> a <A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>VALUES</B></A> <A REL=DEFINITION HREF="../Body/a_type.htm#type"><B>type</B></A> <P>
|
||
|
specifier, multiple <A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>values</B></A> may still be returned.)<P>
|
||
|
<P>
|
||
|
(3) Clarify that it is not an error if the subform returns fewer values<P>
|
||
|
than what is specified by the type specifier. Missing values are<P>
|
||
|
treated as <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> for the purposes of checking their types.<P>
|
||
|
<P>
|
||
|
Rationale for proposal RETURN-NUMBER-RECEIVED:<P>
|
||
|
<P>
|
||
|
Point by point,<P>
|
||
|
<P>
|
||
|
(1) <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> is supposed to act purely as a declaration. It should not<P>
|
||
|
change the number of values that are returned by its subform.<P>
|
||
|
<P>
|
||
|
(2) This is consistent with the way extra values are simply ignored<P>
|
||
|
by <A REL=DEFINITION HREF="../Body/m_multip.htm#multiple-value-bind"><B>MULTIPLE-VALUE-BIND</B></A> and friends.<P>
|
||
|
<P>
|
||
|
(3) This is consistent with the way missing values are treated as <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A><P>
|
||
|
by <A REL=DEFINITION HREF="../Body/m_multip.htm#multiple-value-bind"><B>MULTIPLE-VALUE-BIND</B></A> and friends.<P>
|
||
|
<P>
|
||
|
<P>
|
||
|
<B>Proposal (THE-VALUES:STRICT-MATCHING):<P>
|
||
|
</B><P>
|
||
|
(1) Clarify that the <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> special form returns the exact values as <P>
|
||
|
its subform.<P>
|
||
|
<P>
|
||
|
(2) Clarify that it is an error if the number and syntax of values <P>
|
||
|
returned by the subform do not match the given type specifier<P>
|
||
|
exactly. In particular, if the type specifier is not a <A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>VALUES</B></A><P>
|
||
|
type specifier then only a single value may be returned.<P>
|
||
|
<P>
|
||
|
Rationale for proposal STRICT-MATCHING:<P>
|
||
|
<P>
|
||
|
Point by point,<P>
|
||
|
<P>
|
||
|
(1) <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> is supposed to act purely as a declaration. It should not<P>
|
||
|
change the number of values that are returned by its subform.<P>
|
||
|
<P>
|
||
|
(2) This is consistent with the description of the <A REL=DEFINITION HREF="../Body/a_values.htm#values"><B>VALUES</B></A> type <P>
|
||
|
specifier as specifying the arguments of a function which could<P>
|
||
|
capture the values via <A REL=DEFINITION HREF="../Body/s_multip.htm#multiple-value-call"><B>MULTIPLE-VALUE-CALL</B></A>. Since argument<P>
|
||
|
mismatches are clearly "is an error" situations, this should be<P>
|
||
|
too. This is also apparently closer to current practice than<P>
|
||
|
proposal RETURN-NUMBER-RECEIVED.<P>
|
||
|
<P>
|
||
|
<B>Examples:<P>
|
||
|
</B><P>
|
||
|
Under proposal RETURN-NUMBER-RECEIVED, all of the examples given in <P>
|
||
|
the problem description section are valid and return the values 2 and 1.<P>
|
||
|
<P>
|
||
|
Under proposal STRICT-MATCHING, tests 2, 3, and 5 are in error. Tests<P>
|
||
|
1 and 4 are valid and return the values 2 and 1.<P>
|
||
|
<P>
|
||
|
<B>Current Practice:<P>
|
||
|
</B><P>
|
||
|
Lucid CL version 4.0 signals an error in cases 3 and 5 (at least in the<P>
|
||
|
interpreter). It returns the values 2 and 1 in case 2.<P>
|
||
|
<P>
|
||
|
Allegro CL version 3.1 signals an error in cases 2, 3, and 5.<P>
|
||
|
<P>
|
||
|
<B>Cost to Implementors:<P>
|
||
|
</B><P>
|
||
|
Probably small. Neither proposal requires checking to be performed in<P>
|
||
|
any situation. However under proposal RETURN-NUMBER-RECEIVED, some <P>
|
||
|
implementations will have to be changed to not do some checks they <P>
|
||
|
currently do.<P>
|
||
|
<P>
|
||
|
<B>Cost to Users:<P>
|
||
|
</B><P>
|
||
|
Users may find the stricter error checking permitted by proposal <P>
|
||
|
STRICT-MATCHING helpful. However, if implementations that currently<P>
|
||
|
do not check these errors begin to do so, some programs that currently<P>
|
||
|
work in those implementations to stop working.<P>
|
||
|
<P>
|
||
|
<B>Cost of non-adoption:<P>
|
||
|
</B><P>
|
||
|
Confusion about what the <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> type specifier really means.<P>
|
||
|
<P>
|
||
|
<B>Performance impact:<P>
|
||
|
</B><P>
|
||
|
Probably small, but proposal STRICT-MATCHING might permit compilers<P>
|
||
|
to be more aggressive about some kinds of type and multiple-value<P>
|
||
|
optimizations.<P>
|
||
|
<P>
|
||
|
<B>Benefits:<P>
|
||
|
</B><P>
|
||
|
The cost of non-adoption is avoided.<P>
|
||
|
<P>
|
||
|
<B>Esthetics:<P>
|
||
|
</B><P>
|
||
|
Seems to depend on who you talk to. In the best of all possible<P>
|
||
|
worlds, <A REL=DEFINITION HREF="../Body/m_multip.htm#multiple-value-bind"><B>MULTIPLE-VALUE-BIND</B></A> and friends would have ordinary lambda-list<P>
|
||
|
syntax and follow the same rules as for ordinary lambda-binding, so there <P>
|
||
|
wouldn't be the an inconsistency with <A REL=DEFINITION HREF="../Body/s_multip.htm#multiple-value-call"><B>MULTIPLE-VALUE-CALL</B></A> to have to<P>
|
||
|
resolve one way or the other.<P>
|
||
|
<P>
|
||
|
<B>Discussion:<P>
|
||
|
</B><P>
|
||
|
<P>
|
||
|
This issue was discussed on the common-lisp mailing list some time ago,<P>
|
||
|
but never written up. Here's the last message from that discussion:<P>
|
||
|
<P>
|
||
|
Date: Thu, 20 Apr 1989 17:53 EDT<P>
|
||
|
From: Kent M Pitman <KMP@STONY-BROOK.SCRC.Symbolics.COM><P>
|
||
|
<P>
|
||
|
Date: Thu, 20 Apr 89 16:59:15 EDT<P>
|
||
|
From: Guy Steele <gls@Think.COM><P>
|
||
|
...<P>
|
||
|
PROPOSAL:<P>
|
||
|
<P>
|
||
|
What it boils down to, is that <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> should check only as many types<P>
|
||
|
as requested (and pass back only as many).<P>
|
||
|
<P>
|
||
|
No, this is not cool. <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>THE</B></A> is supposed to act purely as a declaration,<P>
|
||
|
but you are changing it to <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A> it to pass on only as many values<P>
|
||
|
as the type specifer indicates. This could change the semantics of<P>
|
||
|
a suitably devious program.<P>
|
||
|
<P>
|
||
|
Better to say that it checks as many types as requsted, but passes on<P>
|
||
|
exactly the values it receives.<P>
|
||
|
--Guy<P>
|
||
|
<P>
|
||
|
Even though I agree with your position, I think it's worth our writing up<P>
|
||
|
a clarification issue to make sure we're all agreed and that it's 100% <P>
|
||
|
clear in the ANSI spec.<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>
|