Course of Raku / Essentials / Functions essentials
The MAIN function
A Raku program does not need any boilerplate ritual, so you can immediately start writing useful instructions. This part of the program, which is located on the level above any code block (including functions, for example), is called mainline.
If the program contains a function with the special name
MAIN, Raku executes this function after it compiles
everything and after the mainline code has been executed.
say '1. Mainline code';
sub MAIN {
say '3. MAIN called';
}
say '2. Also mainline';This program first executes the top-level says, and then
calls MAIN:
$ raku t.raku
1. Mainline code
2. Also mainline
3. MAIN calledOf course, it is also possible to have a program with the
MAIN function and no other mainline code.
Topics in this section
Practice
Complete the quizzes that cover the contents of this section.
Exercises
This section contains 3 exercises. Examine all the topics of this section before doing the coding practice.
Course navigation
← Solution: Print the warning | Reading command-line arguments →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська