Course of Raku / Addendum 🆕 / Flow and functions / Subroutines and functional style / Exercises

A running accumulator

Problem

Write a subroutine that starts an accumulator at a given value and returns a function which adds to the running total each time it is called and returns the new total. Start at 100, then add 10, 25, and -5, printing each result.

Example

The program prints:

110
135
130

Solution

See the solution

Course navigation

Solution: Compose two functions   |   Solution: A running accumulator