Atom

A counter that remembers its value

The function returned by counter remembers its own start value. A call can use the default step of one or pass a different step.

Atom
func counter(start):
    return func(delta = 1):
        start += delta
        return start

next_value = counter(10)
print(next_value())
print(next_value(3))
Output
11
14

The second call starts at 11 because the first call updated the same captured variable.