Re: Last Element Notation
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Sep 19, 2003
- 506 views
On Fri, 19 Sep 2003 12:30:42 +0000, Al Getz <Xaxo at aol.com> wrote: >Rob had said he doesnt like this idea because he's >checking for negative sequence refs as an error and >apparently he doesnt know how to change to NOT checking >for negative numbers as errors. I would trust Rob understands that all you need is: if idx<0 then idx+=3Dlength()+1 end if followed by normal bounds checking. > >sequence s >s=3D{1,2,3,4} > >[1] >s=3Ds[-3,-1] > >[2] >s=3Ds[$-4,$-2] Actually, that should be s[$-2,$] ) >The only problem that would be left then would be what >to do about <snip>: > >s=3Ds[4-8,-1] > >which generates [-4,-1] ? Mirror or reverse indexing should not stop bounds checking. In existing Eu, if length(s) is 4, then idx<=3D0 or idx>=3D5 error. Permitting backward indexes (LOL!) would change this to: idx<=3D-5 or idx=3D0 or idx>=3D5 error. So it doubles the number of index values which don't cause an error, but you still get a bounds check on anything clearly out of range, and importantly, still on s[0]. >This would have to trigger an error by way of=20 >adding the lenght of the sequence to each number >and comparing with zero to determine if the >reference is indeed too negative. As I said above, inverse or transpose indexes need just: if idx<0 then idx+=3Dlength()+1 -- followed by normal index bounds checking Whatever performance overhead that is, it is certain to be less than remembering which [] the current $ applies to, imo. Of course if people really like the $ symbol, and internally it simply meant -1, they could use it in exactly the same way as proposed.=20 I have no problem with that. Pete