Re: Last Element Reference

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

On Sat, 20 Sep 2003 11:54:49 -0400, jzeitlin at cloud9.net wrote:

>>All i meant was that using a negative index is 'almost' the same
>>as using "$" minus some number.  Let's compare two examples.
>
>>[1] using $
>>s=3D"MyFile.exw"
>>Name=3Ds[1..6]
>>Ext=3Ds[$-3..$]
>
>>[2] using (-) indexing
>>s=3D"MyFile.exw"
>>Name=3Ds[1..6]
>>Ext=3Ds[-4..-1]
>
>>This is why i thought Petes idea was good.
>
>But it does, as was previously indicated, remove the possibility of =
using a check for
>negative subscript as a flaggable error.
No. What it does is double the number of values that can be used to
access an existing element of a sequence, nothing as drastic as
"remove the possibility".=20

Given that you can currently index a sequence of length ten with ten
values, possibly wrongly, changing that to being able to index it with
twenty values, possibly wrongly, does not seem all that scary to me.

Unfortunately, no-one has yet come up with a situation or code snippet
which shows a bug that mirror indexes never trap.

I would also argue that probably more than 9 out of 10 index errors
are out-by-one, which lands nicely on [0] and still triggers an error.

Strange I haven't seen anyone come up with the argument that they
would have to test their software more thoroughly. blink)

>  This might not be a problem if sequences were
>internally (to the Euphoria interpreter) managed as association lists, =
but if they're
>managed as arrays (as seems likely), you're complicating things pretty =
much needlessly.
Rob, from your knowledge of the internals of Euphoria, is my assertion
wrong that the required change would be:
	if a<0 then a+=3Dlength()+1
	-- normal bounds checking
I'm just interested, feel free to say yes and not do it blink

>On the other hand, using "s[$]" isn't any more complicated from the =
interpreter's (and
>Rob's, as the writer of the interpreter) point of view than would be =
using the expression
>s[length(s)] - in fact, the _translator_ could (and probably would) =
generate _exactly_ the
>same code for both.
No. The interpreter has to keep track of what the $ applies to,
whereas length() is explicitly told this.
>
<snip>
>if token-encountered =3D "$" AND expression-context =3D =
sequence-subscript THEN return
>sequence-length
It doesn't happen very often, but which sequence length?
a[$][b[$]..$]

I find the rareness aspect slightly worrying because it makes it so
hard to properly test. Guess I'm glad it's Rob doing it.
>
>(with appropriate use of variables to indicate _which_ sequence the =
current context is
>referring to).
I agree, far more complicated than my suggested approach.

If Rob really doesn't want this (and I think I can assure you he
doesn't), then fine. I'll live.

If you don't want it then fine, just say so, but unfortunately for all
those listening in, it's in my nature, with something I want, to carry
on *discussing* this if you say something I think is wrong blink

Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu