NB. Some changes to cache multiple arguments and work
with boxed arguments, and move mv out of base locale.
coclass'Memo'
lastobj=: ''
create=: 3 : 0
KEY=: ''
VAL=: ''
)
destroy=: codestroy
find=: 3 : 0
if. (#KEY)>i=.KEY i. y do.i{::VAL else. '' end.
)
set=: 4 : 0
KEY=: KEY,< x
VAL=: VAL,< y
)
mv=: 2 : 0
if. 0=#r=. find__n (<y) do.y set__n r=.u y end. r
)
cocurrent 'base'
defm=: 1 : 0
lastobj =: (''conew'Memo')
u mv_Memo_ lastobj
)
NB. lastobj is class field that holds the last object
created. For debuging.
fib4=: (+&fib4 <:)@<:`1:@.(<&2) defm
KEY__lastobj
fib4 25
121393
>KEY__lastobj
1 0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25
the memo class doesnt work with dyads...some attempts
at workarounds, and also example of combining
decorators:
Monadized=:2 : '(>{.n) u (>1{n)'
Monadized2=:1 : '(>{.y) u (>1{y)'
+"0 1 Monadized (2 13; 1 2 3)
3 4 5
14 15 16
+"0 1 Monadized2 (2 13; 1 2 3)
3 4 5
14 15 16
I guess there is no way for a conjunction to bind with
a verb to form a verb instead of adverb? Fortunately
the line below kind of works.
p=: + Monadized2 defm
p 2;2 3 4
4 5 6
p 2;2 3 4 NB. do twice to confirm KEY added just
once
4 5 6
>KEY__lastobj
┌─┬─────┐
│2│2 3 4│
└─┴─────┘
unfortunately, I can't seem to get the undecorated
function to work with alternate ranks.
p"0 1 (2 13;2 3 4)
|length error: p
| (>{.y) u(>1{y)
though this workaround maybe ok in most cases.
p=: +"0 1 Monadized2 defm
p 2 13;2 3 4
4 5 6
15 16 17
p 2;2 3 4
4 5 6
p 2;2
4
Another thing I can't seem to do...
s2=: Monadized (2; 1 2 3) NB. Adverb from conjunction
bond to data
+ s2
3 4 5
but,
p=: + defm
p s
|domain error: p
| (>{.n) u(>1{n)
I believe the error happens because p becomes a monad
as a result of adverb?
Is there a way to modify a dyad?
--- Oleg Kobchenko <[EMAIL PROTECTED]> wrote:
> Unless demonstrated otherwise, there is no such
> thing if
> the tacit expression is a verb, Name has been
> undefined or is a verb
> and fix (f.) is not used. All of which is true for
> those example.
>
> erase nl ''
> 1
> a=: a^:0:
> a
> a^:0:
> a=: a^:0:
> a
> a^:0:
>
> In the concrete examples of memos, the redefinitions
> did not use the previous cache. That's rate of
> performance
> benefit of non-self vs self would be the same on
> first
> and subsequent _definitions_.
>
>
> --- "Miller, Raul D" <[EMAIL PROTECTED]> wrote:
>
> > Oleg Kobchenko wrote:
> > > For some reason the subsequent definitions
> > > with name as opposed to $: just take
> > > more memory on the first call than previous
> definition.
> >
> > a definition of the form
> > Name=: tacit expression using Name
> >
> > Will create a new definition for Name which
> incorporates
> > the previous definition for Name. If Name had
> previously
> > been undefined, this of course does not happen.
> >
> > This is aside from any semantic differences
> between $: and Name.
> >
> > FYI,
> >
> > --
> > Raul
>
>
> __________________________________________________
> 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