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.

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

Course navigation

Creating and calling functions / Positional parameters   |   Creating and calling functions / Default values


💪 Or jump directly to the exercises to this section.

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