Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Clarification of t/spec/S29-array/delete.t

0 views
Skip to first unread message

Patrick R. Michaud

unread,
May 29, 2008, 2:20:15 AM5/29/08
to perl6-c...@perl.org
t/spec/S29-array/delete.t currently has:

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

Chromatic

unread,
May 29, 2008, 3:09:03 AM5/29/08
to perl6-c...@perl.org, Patrick R. Michaud
On Wednesday 28 May 2008 23:20:15 Patrick R. Michaud wrote:

> 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

Moritz Lenz

unread,
May 29, 2008, 5:23:37 AM5/29/08
to chromatic, perl6-c...@perl.org, Patrick R. Michaud

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/

signature.asc
0 new messages