This is what I had in mind:

   (g =. '>@{&paths'&apply f.) NB. instead of (g=. >@{&paths))
'>@{&paths'&(128!:2)

   paths=. 2 ([:  (|. each) (;~ 0$0) , (<\@:+  i.)) 7

   g 4
4 3 2

   g 3 2 $ 2 4 1 5 0
2 0 0 0
4 3 2 0

0 0 0 0
5 4 3 2

0 0 0 0
2 0 0 0

   g 8
8 7 6 5 4 3 2

   paths=. 3 ([:  (|. each) (;~ 0$0) , (<\@:+  i.)) 8

   g 4
5 4 3

   g 3 2 $ 2 4 1 5 0
3 0 0 0
5 4 3 0

0 0 0 0
6 5 4 3

0 0 0 0
3 0 0 0

   g 8
9 8 7 6 5 4 3


This approach is lazy friendly, namely, it is easy to implement and it
can also deal easily with multiple nouns, verbs, adverbs and
conjunctions (to introduce, presumably wanted, side effects).


______________________________________________________________________

On Mon, Jul 23, 2012 at 8:34 AM, Pepe Quintana
<[email protected]> wrote:
> One can also apply the linear representation of a (monadic) verb at run-time 
> using (&apply).  Self-modifying verbs remind me sport motorcycles: 
> dangerously powerful and lots of fun!
>


______________________________________________________________________

On Sun, Jul 29, 2012 at 11:59 PM, Ian Shannon
<[email protected]> wrote:
> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to