Re: Last Element Reference

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

----- Original Message -----  with my scatterings
From: <kbochert at copper.net>
To: "EUforum" <EUforum at topica.com>
Subject: Re: Last Element Reference


>
>
> 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).

They are not the same
s = "123456789" -- so length(s) = 9
now...

s[length(s)-1] = s[3..9-1] = s[3..8]
s[$-1] = s[3..9-1] = s[3..8]
s[-1] = s[3..9-1] = s[3..8]  Ok, I give you this. In one condition.
  You did no math. You used an explicit -1.  A literal -1. Not a variable

Now for the argument:
neg_one = 8-9
s[neg_one] = a freaking negative number for a index value.
Ambigous.  Did you mean to use -1? or did you calculations
put you there by accident.  Should the interpretter throw an error or
happily just assume you meant to look at the last element.

>
> >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