Re: Last Element Reference

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

Pete Lomax wrote:
> Rob, from your knowledge of the internals of Euphoria, is my assertion
> wrong that the required change would be:
> 	if a<0 then a+=length()+1
> 	-- normal bounds checking
> I'm just interested, feel free to say yes and not do it blink

Yes that looks about right, and that's another small point
against negative subscripts. Having to perform
the test:
    if a < 0 then
looks trivial, but subscripting is THE most frequently
performed operation. Adding two machine instructions
would slow down many programs by a couple of percent
when interpreted, and maybe 10 percent when translated,
even if negative subscripts are never used
in that program. It would also add to the size of
translated code, although I could try
to optimize some translated code by "proving" that a
negative subscript will not occur in a given statement.

On the other hand, $ will sometimes speed up the code
and reduce the size of translated code. e.g.
    x[i][1..length(x[i])-1]
vs.
    x[i][1..$-1]

Regards,
    Rob Craig
    Rapid Deployment Software
    http://www.RapidEuphoria.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu