Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.
When I wrote Hangman in Perl 6, I used the following for shuffling a list:
my method shuffle (*@items) {
# Fisher-Yates shuffle
my $i = @items.elems;
while ($i) {
my $j = $i.rand.int;
$i--;
@items[ $i, $j ] = @items[ $j, $i ];
}
return @items;
}
Today I was bothered by this and realized that it's not very Perl 6ish. In fact, Perl 6 is so focused on solving common programmer problems that I realized that the List class should have a shuffle builtin. After much playing around in the internals of Perl 6 and attempting to implement the Fisher-Yates shuffle, I realized that the pick method was better, so I was going to implement it internally with pick, but then I read the documentation more carefully. Shuffling an array in Perl 6 is trivial; the name is just not what I expected.
my @shuffled = @array.pick(*);
Overwriting the array in place (Score:2)
This might even be optimized and actually shuffle the elements within the array.
Re: (Score:2)
Yeah, I'm discovering that as I'm writing tests for my $string.trim function (and it looks like it will be accepted as part of core Perl 6! Yay! :)
Re: (Score:1)
@items.=pick(*);
gets:
Null PMC access in find_method()
if I do either (after:
my $i = @items.elems;
):
@items.=pick($i);
or:
@items = @items.pick($i);
I get:
Cannot assign to readonly variable
Doing:
return @items.pick($i);
works though ('*' again gets the Null PMC).
Re: (Score:2)
That pick seems to work for me:
If you up
Re: (Score:1)
Re: (Score:1)
return @items.pick(*);
works, at least on x86 Leopard box.