Course of Raku / Essentials / More about functions / Multi-functions

Quiz 3 — Calling multi-functions

Here are the three variants of the function.

multi sub func(Int $a) { 1 }
multi sub func(Rat $a) { 2 }
multi sub func(Num $a) { 3 }

Which calls are valid?

1 func(4)  
1 func(4e4)  
1 func(4/4)  
0 func('4') There is no multi sub func(Str $a).
1 func(4.4)  

What do the calls return?

1 func(4) returns  (: 1, 2, 3 :)  
2 func(4.4) returns  (: 1, 2, 3 :) 4.4 is a Rat.
2 func(4/4) returns  (: 1, 2, 3 :) 4/4 is also a Rat number.
3 func(4e4) returns  (: 1, 2, 3 :) A number in scientific notation is Num.

Course navigation

More about functions / Return type   |   💪 Exercise: Factorial with multi-functions

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