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?
| 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
← Named parameters | Quiz 2 — Variables as named parameters →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська