David Green wrote: > Jonathan Lang wrote: > > If C<@foo[last+1]=$bar> is equivalent to C<push @foo, $bar>, what > > happens if you say C<@foo[last+2]=$bar>? While I like the notion that > > subtracting from first or adding to last takes you beyond the bounds > > of the list, you generally can't go more than one beyond either end, > > and then only to add to it. > > I would expect that to work like @foo[$last+2]=$bar does in Perl 5 -- > adds an undef value for @foo[$last+1] and $bar after that. > > I was going to suggest that ordinals wrap around and cardinals "stick > out", but that's probably just begging for subtle confusing errors.
Good point there: if perl 5 does it, we ought to think twice about removing the capability from perl 6. With this in mind, _should_ indices wrap; and if so, when? I think you're right about cardinals not wrapping; if someone assigns to @ints[6] and the existing indices range 0..4, it shouldn't end up assigning to @ints[1]. Likewise, if someone wants to assign to two past the last element, assigning to C<last+2> seems to be common sense; similarly with C<first-3>. The only place where it makes sense to wrap is when you define 0th as the final element, making it logical that 0th+1 == 1st and 1st-1 == 0th. (But what happens if you try to access the 4th or -3rd element of a three-element list? Perhaps Perl should complain?) Maybe the behavior should depend on the list. For normal lists, nothing wraps; if you define the list with C<is ring> or some such, everything wraps. ===== Jonathan "Dataweaver" Lang __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com