Course of Raku / Advanced / Modules / Modules basics / Exercises / Use a stats module
Solution: Use a stats module
Here is a possible solution to the task.
Code
The program, stats.raku:
use Stats;
my @scores = 10, 20, 30, 40;
say "total: { total(@scores) }";
say "mean: { mean(@scores) }";🦋 You can find both source files in the exercises/advanced/modules-basics/stats-module directory.
Output
$ raku -I. stats.raku
total: 100
mean: 25Comments
A single
use Statsbrings in both exported subroutines at once —useimports everything the module marks withis export, not just one name.meancallstotalinside the module. The program never callstotalon its own behalf there, yet it still works: a module’s subroutines can rely on one another, and the caller only sees the exported names.With four numbers adding to
100, the mean is100 / 4, which is25.