Course of Raku / Essentials / Functions 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?

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

2

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

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

Course navigation

Named parameters   |   Quiz 2 — Variables as named parameters

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