Course of Raku / Essentials / The MAIN function

Multiple MAIN functions

Like any other function in Raku, the MAIN function can have its multi variants. It allows the program to individually react to a different number or different types of input parameters.

multi sub MAIN($a) {
    say 2 * $a;
}

multi sub MAIN($a, $b) {
    say $a + $b;
}

This program doubles its only argument or adds it to the second argument if it is present:

$ raku t.raku 21
42

$ raku t.raku 21 33
54

Practice

Complete the quiz that covers the contents of this topic.

Course navigation

The MAIN function / Reading command-line arguments   |   The MAIN function / Using unit sub


💪 Or jump directly to the exercises to this section.

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