my @array = <a b c d>;
is ~@array, "a b c d", "basic sanity (1)";
is ~@array.delete(2), "c",
"deletion of an array element returned the right thing";
# Note: The double space here is correct (it's the stringification of undef).
is ~@array, "a b d", "deletion of an array element";
is ~@array.delete(0, 3), "a d",
"deletion of array elements returned the right things";
is ~@array, " b ", "deletion of array elements (1)";
is +@array, 3, "deletion of array elements (2)";
I believe that the last two tests are wrong -- that after
deleting elements 0 and 3 from the array we should be
left with a 2-element array that stringifies to " b".
In particular, I think that the following sequence should
result in a 0-length array:
my @array;
@array[8] = 'eight'; # array has elements 0..8
@array.delete(8); # now it's empty again
say +@array; # "0\n"
Pugs (evalbot) disagrees with me on this:
06:16 <pmichaud> pugs: my @array; @array[8]='eight'; @array.delete(8); say +@array;
06:16 <exp_evalbot> OUTPUT[8]
Perl 5 agrees with my interpretation, though:
$ cat x
my @array;
$array[8] = 'eight';
delete $array[8];
print 0+@array, "\n";
$ perl x
0
$
Comments?
Pm
> In particular, I think that the following sequence should
> result in a 0-length array:
>
> my @array;
> @array[8] = 'eight'; # array has elements 0..8
> @array.delete(8); # now it's empty again
> say +@array; # "0\n"
>
> Pugs (evalbot) disagrees with me on this:
>
> 06:16 <pmichaud> pugs: my @array; @array[8]='eight'; @array.delete(8);
> say +@array; 06:16 <exp_evalbot> OUTPUT[8]
>
> Perl 5 agrees with my interpretation, though:
>
> $ cat x
> my @array;
> $array[8] = 'eight';
> delete $array[8];
> print 0+@array, "\n";
> $ perl x
> 0
> $
>
> Comments?
S29 suggests that this should be the case:
Deleted elements at the end of an Array shorten the length of the Array,
unless doing so would violate an is shape() definition.
http://perlcabal.org/syn/S29.html#Array
-- c
I added that as a test (+smartlink).
I also fixed the other four offending tests. Rakudo now passes all of
t/S29-array/delete.t
Cheers,
Moritz
--
Moritz Lenz
http://moritz.faui2k3.org/ | http://perl-6.de/