There is another solution.
Make your noun into a verb as in:
NB. just a few helpers, could be defined later.
pathA =: [: (|. each) (;~ 0$0) , (<\@:+ i.) NB. calculation of the data
pathB =: <\ i. NB. Either monadic or dyadic hook, possible
pathC =: (2 pathA 7)"_ NB. Set the noun into a verb
NB. Define your verb, this definition doesn't change
NB. At this point "paths" must be either undefined or a verb!
g =. >@{ paths NB. This is now a hook
NB. we specify what the paths are that verb g is to use.
paths =: 2 pathA 7: NB. This constant verb (fork) corresponds
NB. to your first example data
g 4
g 3 2 $ 2 4 1 5 0
g 8
paths =: pathC NB. This also corresponds
NB. to your first example data
g 4
g 3 2 $ 2 4 1 5 0
g 8
paths =: 3 pathB 16"_ NB. Another constant verb (also a fork)
g 4
g 3 2 $ 2 4 1 5 0
g 8
paths =: _3 pathB 16"_ NB. Another constant verb (also a fork)
g 4
g 3 2 $ 2 4 1 5 0
g 8 NB. gives an error!
Ian
Ian Shannon
Landscape Modelling & Decision Support
Scientific Services
Office of Environment and Heritage
Department of Premier and Cabinet
PO Box A290
Sydney South
NSW 1232
T: +61 2 99 955 490
E: [email protected]
-----Original Message-----
On Jul 22, 2012 1:32 PM, "David Vaughan" <[email protected]> wrote:
> I have a noun called paths, whose value changes at various points, and a
> verb g that uses paths. The problem is, it only works for the initial value
> of paths.
>
> paths =: \:~&.> (;~ 0$0) , <\ 2+i.7
> paths
>
>
> g =. >@{&paths
> g
> @{&((0$0);(0$0);(,2);3 2;4 3 2;5 4 3 2;6 5 4 3 2;7 6 5 4 3 2;8 7 6 5 4 3 2)
>
> So now when paths changes, g becomes useless.
>
> My question is how can I get g to always check the value of paths when it
> is executed? And more generally, how can the name of a noun rather than the
> value of the noun be used in a verb?
>
> Many thanks.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
This email is intended for the addressee(s) named and may contain confidential
and/or privileged information.
If you are not the intended recipient, please notify the sender and then delete
it immediately.
Any views expressed in this email are those of the individual sender except
where the sender expressly and with authority states them to be the views of
the Office of Environment and Heritage, NSW Department of Premier and Cabinet.
PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING THIS EMAIL
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm