Thanks Jorge.  Here is the final program below for anyone interested.

myadverb =: 1 : 0
parameters =. (( (TAB ~: ]) *. (' ' ~: ]) *. (LF ~: ])) # ]) ((5!:5) <'u' ),
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 y
( 3!:1 data ) fwrite fname
else.
('using previously cached result...') (1!:2) 2
data =. ( 3!:2 fread fname )
end.
data
)


On 4/24/08, Jorge Arredondo <[EMAIL PROTECTED]> wrote:
>
> You can use 5!:5 to get the string representation of u, for instance:
>    a=: 1 : '(5!:5<''u'')'
>    '+/' -: +/ a
> 1
>
>
> On Thu, Apr 24, 2008 at 8:08 AM, Matthew Brand <[EMAIL PROTECTED]>
> wrote:
> > 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
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to