Re: Last Element Reference
- Posted by Robert Craig <rds at RapidEuphoria.com> Sep 21, 2003
- 497 views
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 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