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

Quiz 2 — Multi-functions with typed parameters

What are the correct ways to create a multi-function?

1

multi sub func(Int $a, Int $b) {. . .}
multi sub func(Int $a, Num $b) {. . .}
correct These definitions are  (: correct, incorrect :) Parameter types differ.

2

multi sub func(Int $a, Int $b) {. . .}
multi sub func(Int $a, Int $b, Int $c) {. . .}
correct These definitions are  (: correct, incorrect :) Number of parameters differs.

3

multi sub func($a) {. . .}
multi sub func(Int $a, Int $b) {. . .}
multi sub func(Int $a, Int $b, Int $c) {. . .}
correct These definitions are  (: correct, incorrect :) A variant with positional-only parameter is fine.

4

multi sub func($a) {. . .}
multi sub func(Int $a) {. . .}
correct These definitions are  (: correct, incorrect :) The first variant catches everything but Int.

Course navigation

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

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