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

Quiz 1 — Named parameters

Consider a function:

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

1

What are the valid ways to call it?

0 f(1, 2) Positional arguments passed, not named.
1 f(a => 1, b => 2)  
0 f(a = 1, b = 2) Assignment operator instead of a pair constructor.
1 f(b => 2, a => 1)  

2

For the same function, what do the following calls return?

−1 f(a => 1, b => 2) returns  (: 1, −1 :)  
−1 f(b => 2, a => 1) returns  (: 1, −1 :) The order of named arguments does not matter.
1 f(a => 2, b => 1) returns  (: 1, −1 :)  

Course navigation

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


💪 Or jump directly to the exercises to this section.