p j wrote:
> Only because of the need for a static variable. Pretty
> hard to come up a non-object version for handling
> static variables, but I maintain its unrelated to
> closures.
I agree with p j.
Here's an implementation which does not use closures nor objects:
".(0>nc<'N')#'N=:a:'
acc=:3 :0
n=.":#N
N=:N,<y
3 :('n{::N=:N n}~<y+N{::~n=.',n)`''
)
Example use:
f=: (acc 7)`:0
f 3
10
f 3
13
Of course, you have to use this correctly, or it won't work.
But that seems to be characteristic of any computer program.
g=: (acc i. 2 2)`:0
g 8
8 9
10 11
g 9
17 18
19 20
g 10 11
27 28
30 31
g 12 13 14
|length error: g
| n{::N=:N n}~<y +N{::~n=.3
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm