r=:0
   TEST=:3 :'r=:y+r'
   TEST"0 ]5#,:i.10
  0   1   3   6  10  15  21  28  36  45
 45  46  48  51  55  60  66  73  81  90
 90  91  93  96 100 105 111 118 126 135
135 136 138 141 145 150 156 163 171 180
180 181 183 186 190 195 201 208 216 225

Does the trick: run TEST on an array. However, a warning: the order of
execution is not guaranteed. It is probably much better to implement this
using a for. loop.

Marshall

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Robert O'Boyle
Sent: Sunday, March 13, 2011 10:35 PM
To: [email protected]
Subject: [Jprogramming] Recursive algorithm

Hi Forum

 

I am doing some MCMC work and have been fiddling around with different ways
to implement this in J. In my testing, I have a short program, TEST, which
adds a number to an existing one, r.

 

r =: 0

 

TEST =: 3 : 0

r=: y+r

)

 

I'd like to execute TEST many times but always using the last value of r. I
can do this by building scripts within scripts but think that there has to
be a better way. I tried 

 

(TEST"0  i.10) "0 i.5

 

to execute TEST 5 times but got

 

0 1 3 6 10 15 21 28 36 45

0 1 3 6 10 15 21 28 36 45

0 1 3 6 10 15 21 28 36 45

0 1 3 6 10 15 21 28 36 45

0 1 3 6 10 15 21 28 36 45

 

rather than the desired

 

  0   1   3   6  10  15  21  28  36  45

 45  46  48  51  55  60  66  73  81  90

 90  91  93  96 100 105 111 118 126 135

135 136 138 141 145 150 156 163 171 180

180 181 183 186 190 195 201 208 216 225

 

Any help would be appreciated

 

Bob

 

----------------------------------------------------------------------
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