Course of Raku / Advanced / Modules / Modules basics / Exercises / Two functions in one module

Solution: Two functions in one module

Here is a possible solution to the task. It uses two files.

Code

The module, Calc.rakumod:

unit module Calc;

sub add($a, $b) is export {
    $a + $b
}

sub mul($a, $b) is export {
    $a * $b
}

The program, calc.raku:

use Calc;

say add(3, 4);
say mul(3, 4);

🦋 You can find both source files in the exercises/advanced/modules-basics/two-functions directory.

Output

$ raku -I. calc.raku
7
12

Comments

  1. A module can export as many subroutines as you like; each one carries its own is export trait.

  2. Both add and mul become available in the program after a single use Calc.

Course navigation

Two functions in one module   |   Use the converter