Course of Raku / Essentials / Creating and calling functions / Named parameters

Quiz 2 — Variables as named parameters

Here is the same function as in the previous quiz:

sub f(:$a, :$b) {
    $a - $b
}

You also have three variables in the program:

my $a = 1;
my $b = 2;
my $c = 3;

Mark all the valid ways to call the function and pass two of the three variables to it.

1f(a => $a, b => $b)
1f(a => $c, b => $c)
0f($a, $b)Positional arguments are passed here instead of the named ones.
1f(:$a, :$b)
0f($:a, $:b)Not a valid Raku syntax.
0f(:$b, :$c)No named parameter c.
0f(:$a, c => $c)No named parameter c.
1f(:$a, b => $c)
1f(:$a, :b($c))Same as above.
1f(:a($a), :b($c))Also fine, while a bit redundant.

Course navigation

Quiz 1 — Named parameters   |   Default values

Translations of this page: EnglishDeutschEspañolItalianoLatviešuNederlandsБългарскиРусскийУкраїнська