3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
6 # The `accumulator factory` task.
7 # SEE: <http://rosettacode.org/wiki/Accumulator_factory>
9 # Nit has no first-class function.
10 # A class is used to store the state.
11 module accumulator_factory
15 # Numeric is used, so Int and Float are accepted
16 private var sum
: Numeric
17 fun call
(n
: Numeric): Numeric
19 # `add` is the safe `+` method on Numeric
25 var x
= new Accumulator(1)
27 var y
= new Accumulator(3)