Course of Raku / Advanced / Subroutines / Nested subroutines / Exercises / A private helper

Solution: A private helper

Here is a possible solution to the task.

Code

sub stats {
    sub double($x) { $x * 2 }

    say double(3) + double(5);
}

stats;

🦋 You can find the source code in the file private-helper.raku.

Output

16

Comments

  1. The helper double is defined inside stats, so it is visible only there and cannot be called from elsewhere in the program.

  2. stats uses it twice: double(3) is 6 and double(5) is 10, and their sum is 16.

Course navigation

A private helper   |   Closing over the outer