Course of Raku / Essentials / Functions essentials / More about functions / Typed parameters

Quiz — Typed parameters

1

Given the function:

sub f(Rat $x) {
    say 2 * $x;
}

Which calls are correct?

0f(3);Even if 3 can fit in a Rat container, the call is wrong as 3 is Int, not a Rat.
1f(3.5);
0f(3e0);
0f('3');
1f(<4/5>);This is a Rat number.

2

Given the function:

sub g(Int $a, Str $b) {
    say "Integer $a, string $b";
}

Which calls are correct?

0g(10, 20);
0g('10', 20);Even if either argument can be cast, Raku demands the exact type.
1g(10, '20');
0g('10, 20');A single string passed.
0g('10', '20');

Course navigation

Typed parameters   |   Return type

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