Multiplication with Perl 6 Sequence Whatever (...) operator

For one thing, Perl 6 is sensitive to whitespace.

1, 2, * * * ... *

is perfectly legitimate and generates a sequence that's sort of like a multiplicative fibonacci; it's just a little bit hard to read. *** and * * * mean something different.

If the ambiguity bothers you, you can use an explicit block instead of the implicit one that using "whatever star" gives you:

1, 2, -> $a, $b { $a * $b } ... *

and

1, 2, { $^a * $^b } ... *

both produce the same sequence as 1, 2, * * * ... * does (tested in Rakudo).


my @powers_of_two := { 1, 2, { $^a * 2 } ... *);

my $n = 6;
my @powers_of_six := { 1, $n, { $^a * $n } ... *);

Tags:

Perl

Raku