Re: Last Element Reference

new topic     » goto parent     » topic index » view thread      » older message » newer message

On 20 Sep 2003 at 20:35, jzeitlin at cloud9.net wrote:

> 
> 
> On Sat, 20 Sep 2003 17:02:14 -0700, Al Getz <Xaxo at aol.com> wrote:
> 
> >jzeitlin at cloud9.net wrote:
> 
> [deleted for bandwidth]
>  

> >So you're telling me you dont have to check for negative
> >subscripts here:
> >s={1}
> >s=s[$-1000,$-2000]
> 
> No, I'm NOT.  You absolutely have to check for negative subscripting, and Rob
> has already
> included this code in the Euphoria interpreter - you will get an error if you
> try to take
> s[-1].
> 
> Your proposal, of allowing negative subscripts without the $, requires
> significant
> internal programmatic change to the interpreter - 
Sorry, no.
   s[3..$-1]
and
   s[3..length(s)-1]
and 
   s[3..-2]
are exactly the same thing expressed with different characters.
The final form is the easiest of the three for the interpreter (2 lines of C in
Bach).

>and removes the ability to flag an error
> if a negative subscript is encountered.  Because a negative subscript actually
> would mean
> something legitimate.
> 
No reduction of error checking occurs.  In both cases, the index is checked
against the bounds of the sequence.  The only difference is where the
index calculation occurs, and in fact the 'negative index' is superior in that
the "length(s)-x" occurs in compiled C code instead of interpreted Euphoria.

Karl Bochert

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu