Course of Raku / Advanced / Subroutines / Nested subroutines / Exercises / An inner sum
Solution: An inner sum
Here is a possible solution to the task.
Code
sub compute {
sub add($x, $y) {
$x + $y;
}
add(2, 3) + add(4, 5);
}
say compute;🦋 You can find the source code in the file inner-sum.raku.
Output
14Comments
The nested
addis used twice insidecompute:add(2, 3)is5andadd(4, 5)is9.Their sum,
14, is the value returned bycompute.