For some reason the subsequent definitions
with name as opposed to $: just take
more memory on the first call than previous definition.
Otherwise, they use a fresh cache just after the
definition (not reusing previous calls of the same name).
fib2=: (+&fib2 <:)@<:`1:@.(<&2) defm NB. first time
5 ts'fib2 25'
5.43169e_5 16256
5 ts'fib2 25'
4.86037e_5 4160
fib2=: (+&fib2 <:)@<:`1:@.(<&2) defm NB. second time
5 ts'fib2 25'
5.16009e_5 23040
5 ts'fib2 25'
5.32539e_5 4160
fib3=: (+&fib3 <:)@<:`1:@.(<&2) defm NB. new name time
5 ts'fib3 25'
5.19172e_5 54016
5 ts'fib3 25'
5.24279e_5 4160
fib3=: (+&$: <:)@<:`1:@.(<&2) defm NB. Self recurse
5 ts'fib3 25'
5.20134e_5 16256
5 ts'fib3 25'
4.97499e_5 4160
--- p j <[EMAIL PROTECTED]> wrote:
> Another note, if you use the verb name instead of $:
> in the definition, then the function uses the cached
> data when it recurses.
>
> fib4=: (+&fib4 <:)@<:`1:@.(<&2) defm
>
> --- Oleg Kobchenko <[EMAIL PROTECTED]> wrote:
>
> > NB.
> >
> =========================================================
> > coclass 'pmem'
> >
> > create=: 3 : 0
> > KEY=: ''
> > VAL=: ''
> > )
> > destroy=: codestroy
> > find=: 3 : 0
> > if. (#KEY)>i=.KEY i.boxopen y do.i{::VAL else. ''
> > end.
> > )
> > set=: 4 : 0
> > KEY=: KEY,boxopen x
> > VAL=: VAL,boxopen y
> > )
> > cocurrent 'base'
> >
> > mv=: 2 : 0
> > if. 0=#r=. find__n y do.y set__n r=.u y end. r
> > )
> >
> > defm=: 1 : 0
> > u mv (''conew'pmem')
> > )
> > NB.
> >
> =========================================================
> >
> >
> > fib1=: (+&$: <:)@<:`1:@.(<&2)
> > fib2=: (+&$: <:)@<:`1:@.(<&2) defm
> >
> > fib2"0 i.20
> > 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
> > 2584 4181 6765
> >
> > (fib2 (-: , ]) fib1) 25
> > 1 121393
> >
> >
> > 5 ts'fib1 25'
> > 0.343449 14720
> >
> > 5 ts'fib2 25'
> > 5.1219e_5 4160
> >
> > 0.343449 % 5.1219e_5
> > 6705.5
> >
> >
> >
> >
> > --- p j <[EMAIL PROTECTED]> wrote:
> >
> > > define an adverb A such that:
> > >
> > > f A = 'f'
> > >
> > > that is for any verb f, f A returns the string
> > that
> > > names f.
> > >
> > > If this is currently impossible, is there a way to
> > use
> > > the 5!: functions such that f A generates a unique
> > > string for any value of f.
> > >
> > > A =: 1 : '5!:5 < ''u.''' NB. generates a string
> > for
> > > the functionality of u. instead of the name of u.
> > >
> > > If none of this can be done, has anyone come up
> > with a
> > > method to memoize results of a verb?
> > >
> >
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325905
> > >
> >
> >
> > __________________________________________________
> > 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
> >
>
>
> __________________________________________________
> 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
>
__________________________________________________
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