Placeholder blocks

Anonumous blocks not only can contain the code but also can make use of parameters passed to them. Unlike the Arrow blocks (lambdas), you don't need lising all the arguments but rather may use them directly when they are needed.

Placeholder varialbes go with the caret twigil, for example: $^x and are ordered according to their Unicode order. Thus, a block using variables, $^x and $^y, expects $^x to be the first parameter and $^y to be the second one:

my $pow = {$^x ** $^y};
say $pow(3, 4); # 81

Similarly, placeholder blocks can be used in loops:

for 0..9 {
    say $^n2, $^n1;

In this example, $^n2 is the second argument and $^n1 is the first. Thus, the block consumes two items at a moment, and the loop will be repeated five times, and the first pass will print 10.

Note that there is no arrow anymore before the start of the block. Presence of the arrow would suggest the presence of implicitly spelled arguments.

Placeholder variables can be named. In this case instead of the caret a semicolon (:) is used as a twigil:

my $pow = {$:base ** $:exp};
say $pow(:base(25), :exp(2)); # 625

Now, it does not matter in which order you pass the values to the function. The following call gives exactly the same result:

my $pow = {$:base ** $:exp};
say $pow(:exp(2), :base(25)); # 625