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

Quiz — Typed parameters

1

Given the function:

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

Which calls are correct?

0 f(3); Even if 3 can fit in a Rat container, the call is wrong as 3 is Int, not a Rat.
1 f(3.5);  
0 f(3e0);  
0 f('3');  
1 f(<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?

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

Course navigation

More about functions / Mind the space   |   More about functions / Return type


💪 Or jump directly to the exercise to this section.