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

134 lines
7.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 SUBSEQ-OUT-OF-BOUNDS 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/iss331_w.htm">
<LINK REL=UP HREF="../Issues/iss332.htm">
<LINK REL=NEXT HREF="../Issues/iss333_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/iss331_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss332.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss333_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue SUBSEQ-OUT-OF-BOUNDS Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss332.htm">SUBSEQ-OUT-OF-BOUNDS</A><P>
<P>
<B>References:</B> :START and :END arguments (246-247), <A REL=DEFINITION HREF="../Body/f_subseq.htm#subseq"><B>SUBSEQ</B></A> (248)<P>
<P>
<B>Category:</B> CLARIFICATION<P>
<P>
<B>Edit history:</B> 24-Mar-88, Version 1 by Steele<P>
29-Mar-88, Version 2 by Steele, in response to Moon's comments<P>
<P>
<B>Problem description:<P>
</B><P>
The descriptions of :START and :END arguments, and of <A REL=DEFINITION HREF="../Body/f_subseq.htm#subseq"><B>SUBSEQ</B></A>, do not<P>
explicitly address the question of out-of-bounds indices. (The language on<P>
page 246, &quot;These arguments should be integer indices into the sequence,&quot; is<P>
considered too vague on this point.)<P>
<P>
Also, the language on page 246 does not make clear whether the prohibition<P>
against &quot;start &gt; end&quot; applies to defaulted values as well as explicit<P>
values, and does not specify clearly whether the default value for the<P>
end argument is the allocated length or the active length.<P>
<P>
<P>
<B>Proposal (SUBSEQ-OUT-OF-BOUNDS:IS-AN-ERROR):<P>
</B><P>
Specify that it is an error for the :START argument of any <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A><P>
function, or the second argument to <A REL=DEFINITION HREF="../Body/f_subseq.htm#subseq"><B>SUBSEQ</B></A>, to be less than zero.<P>
<P>
Specify that it is an error for the :END argument of any <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> function,<P>
or the third argument to <A REL=DEFINITION HREF="../Body/f_subseq.htm#subseq"><B>SUBSEQ</B></A>, to be greater than the active length of<P>
the sequence in question (as returned by <A REL=DEFINITION HREF="../Body/f_length.htm#length"><B>LENGTH</B></A>).<P>
<P>
Specify that the start value, after defaulting, must not be greater than<P>
the end value, after defaulting.<P>
<P>
Specify that the default value for the end argument is the active length of<P>
the sequence in question.<P>
<P>
This may be summarized as follows:<P>
<P>
Let X be the sequence within which indices are to be considered. Let S be<P>
the :START argument of any <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> function, or the second argument to<P>
<A REL=DEFINITION HREF="../Body/f_subseq.htm#subseq"><B>SUBSEQ</B></A>, whether explicitly specified or defaulted, through omission, to<P>
zero. Let E be the :END argument of any <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> function, or the third<P>
argument to <A REL=DEFINITION HREF="../Body/f_subseq.htm#subseq"><B>SUBSEQ</B></A>, whether explicitly specified or defaulted, through<P>
omission or an explicitly passed <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> value, to the active length of X, as<P>
returned by <A REL=DEFINITION HREF="../Body/f_length.htm#length"><B>LENGTH</B></A>. It is an error if the condition (<A REL=DEFINITION HREF="../Body/f_eq_sle.htm#LTEQ"><B>&lt;=</B></A> 0 S E (<A REL=DEFINITION HREF="../Body/f_length.htm#length"><B>LENGTH</B></A> X))<P>
is not true.<P>
<P>
<B>Test Cases/Examples:<P>
</B><P>
(<A REL=DEFINITION HREF="../Body/f_subseq.htm#subseq"><B>SUBSEQ</B></A> &quot;Where's the beef?&quot; -1 5) might be assumed to be &quot;Where&quot; or &quot; Where&quot;.<P>
<P>
(<A REL=DEFINITION HREF="../Body/f_subseq.htm#subseq"><B>SUBSEQ</B></A> &quot;Where's the beef?&quot; -3 -3) might be assumed to be &quot;&quot;.<P>
<P>
(<A REL=DEFINITION HREF="../Body/f_subseq.htm#subseq"><B>SUBSEQ</B></A> &quot;Where's the beef?&quot; 16 18) might be assumed to be &quot;?&quot; or &quot;? &quot;.<P>
<P>
(<A REL=DEFINITION HREF="../Body/f_subseq.htm#subseq"><B>SUBSEQ</B></A> &quot;Where's the beef?&quot; 10000 10000) might be assumed to be &quot;&quot;.<P>
<P>
Under this proposal each of these situations is an error, and portable<P>
programs may not rely on their behavior.<P>
<P>
<B>Rationale:<P>
</B><P>
We don't want code indexing off the ends of arrays.<P>
<P>
<B>Current practice:<P>
</B><P>
KCL interpreted and compiled code signals an error.<P>
<P>
Symbolics Common Lisp interpreted and compiled code signals an error; the<P>
compiler also issued an out-of-range warning (possible because the<P>
arguments were all constant).<P>
<P>
Lucid Common Lisp interpreted and compiled code signals an error.<P>
<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
None.<P>
<P>
<B>Cost to Users:<P>
</B><P>
Users who depended on some specific implementation behavior in these cases<P>
may find that their pragmatically unportable code is now officially<P>
unportable.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
Confusion.<P>
<P>
<B>Benefits:<P>
</B><P>
Removal of a small but important ambiguity in the spec.<P>
<P>
<B>Esthetics:<P>
</B><P>
It seems cleaner not to allow indexing off the end of an array, and<P>
by extension not allow it for any sequence.<P>
<P>
<B>Discussion:<P>
</B><P>
This merely clarifies the original intent of the passage on page 246.<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>