At Fri, 3 Sep 2004 17:08:00 -0700, [EMAIL PROTECTED] (Larry Wall) wrote: > > On Fri, Sep 03, 2004 at 05:45:12PM -0600, John Williams wrote: > : If not, does @ints[-1] mean the element with index -1 or the last element? > > The element with index -1. Arrays with explicit ranges don't use the > minus notation to count from the end. We probably need to come up > with some other notation for the beginning and end indexes. But it'd > be nice if that were a little shorter than: > > @ints.shape[0].beg > @ints.shape[0].end > > Suggestions? Maybe we just need integers with "whence" properties... :-)
I think "@ints[-11]" is the obvious choice! Also, it might be a decent default to have array parameters (or any bindings) automatically readjust their indices to [0..$#array] unless explicitly declared otherwise: sub f1(@a) { @a[0] } sub f2(@a is shape(:natural)) { @a[0] } sub f3(@a is shape(-2..(-2 + @a.len))) { @a[0] } my @array is shape(-1..1) = 1..3; f1(@a); # ==> 1 f2(@a); # ==> 2 f3(@a); # ==> 3 That way, any code using non-zero-based indices would be clearly marked as such, which seems prudent -- I know I don't use "$[" where appropriate, and usually assume that "$#x + 1 == @x". /s