This is what I have in mind: (to run it you must create directory
c:\data\cache or change the "dir" variable).

myadverb =: 1 : 0
NB. y is a string already, but how do I convert the input verb "u" into a
string?
NB.parameters =. <convert verb u to a string> , y
parameters =. y
dir =. 'C:\data\cache\'
fname =. dir, 'myadverb', ": ( 2: { [: ; (0: s: 2:) {~ [: 6&s: [: s: ' '&~:
# ]) (3!:1) parameters
if. 0 = # (1!:0) fname do.
('calculating result and caching...') (1!:2) 2
data =. u i. # y NB. would normally be data =. u y
( 3!:1 data ) fwrite fname
else.
('using previously cached result...') (1!:2) 2
data =. ( 3!:2 fread fname )
end.
data
)

Examples:
+/\ myadverb 'inputA'
calculating result and caching...
0 1 3 6 10 15
+/\ myadverb 'inputB'
calculating result and caching...
0 1 3 6 10 15
+/\ myadverb 'inputA'
using previously cached result...
0 1 3 6 10 15
+/\ myadverb 'inputB'
using previously cached result...
0 1 3 6 10 15


How can I get the text that is the program code for the input verb (u) so
that I can generate the hash for it though? I.e. how do I turn u into the
string '+/\' so that I can concatenate it with y?


Thanks,
Matthew.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to