Accumulator factory: Difference between revisions

no edit summary
No edit summary
Line 1,665:
y = acc() -- create new function with factory's sum as initial value
print (y()) --> 4 -- print the accumulated value inside the product y</lang>
 
=={{header|M2000 Interpreter}}==
 
 
\\ M2000 Interpreter
 
\\ accumulator factory
 
foo=lambda (n as double) -> {
=lambda n (x) -> {
\\ x has no type here, can be any numeric type (also can be an object too)
\\ accumulator is double, and is a closure (a copy of n in foo)
n+=x
\\ any variable in M2000 hold first type
\\ if x is an object then we get error, except if object use this operator
x=n
\\ so we return x type
=x
}
}
 
x=foo(1)
 
call void x(5)
 
call void foo(3)
 
print x(2.3) ' prints 8.3
 
=={{header|Maple}}==
Anonymous user