I've worked over the basic list operations in S29 (see below, as I can't
commit). The big shocker is going to be this: splice can't be as
full-featured as we wanted. According to audreyt on #perl6, Perl 6.0.0
cannot expect to have MMD on both the inbound and outbound signature.
Given that, we'll have to replace:
splice(@foo,1,5) = 1..^$end;
splice(@foo,1,5) <== 1..^$end;
I'm also doing away with sub wherever I can, since all core functions
probably need to be "multi sub" there's no reason to be explicitly
redundant. S06 tells us that "sub" is the default when multi or proto
Here's the full text for the changed section:
our Scalar multi Array::pop ( @array is rw )
our Scalar multi method Array::pop ( @array: )
Remove the last element of C<@array> and return it.
our Int multi Array::push ( @array is rw, [EMAIL PROTECTED] )
our Int multi mehtod Array::push ( @array: [EMAIL PROTECTED] )
Add to the end of C<@array>, all of the subsequent arguments.
our Scalar multi Array::shift ( @array is rw )
our Scalar multi method Array::shift ( @array: )
Remove the first element from C<@array> and return it.
our List multi Array::splice( @array is rw, Int $offset = 0, Int $size?,
[EMAIL PROTECTED] )
C<splice> fills many niches in array-management, but its fundamental behavior
is to remove zero or more elements from an array and replace them with a
new (and potentially empty) list. This operation can shorten or lengthen
the target array.
C<$offset> is the index of the array element to start with. It defaults
C<$size> is the number of elements to remove from C<@array>. It defaults
to removing the rest of the array from C<$offset> on.
The slurpy list of values (if any) is then inserted at C<$offset>.
Calling splice with a traditional parameter list, you must define C<$offset>
and C<$size> if you wish to pass a replacement list of values. To avoid
having to pass these otherwise optional parameters, use the piping operator(s):
splice(@array,10) <== 1..*;
which replaces C<@array> and all subsequent elements with an infinite
series starting at C<1>.
This behaves similarly to Perl 5's C<splice>.
If C<@array> is multidimensional, C<splice> operates only on the first
dimension, and works with Array References.
our Int multi Array::unshift ( @array is rw, [EMAIL PROTECTED] )
our Int multi method Array::unshift ( @array: [EMAIL PROTECTED] )
C<unshift> adds the values onto the start of the C<@array>.
Aaron Sherman <[EMAIL PROTECTED]>
Senior Systems Engineer and Toolsmith
"We had some good machines, but they don't work no more." -Shriekback