>>58
There's a metaop in
>>12. According to the periodic table of ops, '=>' is "fiddly", and so meta '=>' is illegal:
http://glyphic.s3.amazonaws.com/ozone/mark/periodic/Periodic%20Table%20of%20the%20Operators%20A4%20300dpi.jpg
The table must be outdated, since '%' is listed as "iffy" (i.e. you can !%), but if you try that, Rakudo rejects it and prompts you to use %% instead.
You want junctions? Here's a variation from perl6-examples:
sub blackjack (@cards) {
given [+] map { $^a < 11 ?? $a !! $a|1 }, @cards {
when 21 { return 'blackjack!' };
when * < 21 { return 'ok.' };
when True { return 'bust!' };
}
}
say blackjack(<1 2 3>);
say blackjack(<11 10 10>);
say blackjack(<11 11 10 10>);
There's more interesting stuff happening in the original:
http://github.com/perl6/perl6-examples/blob/master/games/blackjack.p6 notably:
my @values = (ace => 1|11, two => 2, three => 3, four => 4, five => 5, six => 6, seven => 7, eight => 8, nine => 9, ten => 10, jack => 10, queen => 10, king => 10, );
my @suites = < spades clubs diamonds hearts >;
my @deck = ( @values X @suites ).map: { my ($name, $value) = $^a.kv; $name ~= " of $^b"; $name => $value };
Here the deck is the Cartesian product of Ace .. King with the various suits. In other versions I've seen the deck sorted in place with:
@deck.=pick(*) (i.e.
@deck = @deck.pick(@deck.elems))
There was a big fuss about this, which lazily evaluates Pascal's triangle:
sub pascal { [1], -> @p { [0, @p Z+ @p, 0] } ... * }
.say for pascal[^10];