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

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

What do the calls return?

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

Course navigation

Quiz 2 — Multi-functions with typed parameters   |   Factorial with multi-functions

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