Here is a variation
foo=: 1 : 0
a=. cocreate''
n__a=: m
a&(4 : 'n__x=: n__x + y')
)
f=. 3 foo
f 0
3
f 2
5
f 5
10
f 0
10
conames 1
0 1 10 11 12 13 14 15 16 17 22
f
(<'22')&(4 : 'n__x=: n__x + y')
(erase,[:coerase[:0&{::5!:2)<'f'
1 1
f
|value error: f
conames 1
0 1 10 11 12 13 14 15 16 17
Note: global variables closers by bonding
--- Chris Burke <[EMAIL PROTECTED]> wrote:
> June Kim wrote:
>
> >Hello
> >
> >How could I make a higher-order function in J?
> >
> >I mean,
> >
> > add4=: add 4
> > add4 13
> >17
> > add5=: add 5
> > add5 13
> >18
> >
> >Also related but not identical is accumulator
> >generator(http://www.paulgraham.com/accgen.html ).
> >
> >
> An accumulator generator:
>
> foo=: 1 : 0
> n=. 'n_',(> cocreate''),'_'
> (n)=. m.
> 3 : (n,'=:',n,'+y.')
> )
>
> add=: 7 foo
> add 10
> 17
> add 100
> 117
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm