Why didn't it work? I think drowned in complexity...

Trying to understand/simplify what you said, I think something like

   inc =: 4 : '(>: x.{y.) x.}y.'
   dec =: 4 : '(<: x.{y.) x.}y.'

may be what you were getting at. e.g.

   a =: 0 0 0 0 0 0 0 0

   ]a =: 3 inc a
0 0 0 1 0 0 0 0

   5 2 inc^:4 a  NB. increment items 5 and 2 - do it 4 times.
0 0 4 0 0 4 0 0

   1 3 dec i. 5 6  NB. extends nicely, decrement rows 1 and 3.
 0  1  2  3  4  5
 5  6  7  8  9 10
12 13 14 15 16 17
17 18 19 20 21 22
24 25 26 27 28 29

- joey

At 22:20  -0500 2006/03/25, Nicholas Spies wrote:
To conceal some of the visual noise implicit in J, I (foolishly, no doubt) tried to do the following:

NB. define  an array in which to store data
a =: 0 0 0 0 0 0 0 0

NB. simple enough
get  =: 4 : 'x.{ y.'

set =: 4 : '({. x.) (({: x.)}) y.'

  ]a =: 3 0 set a
3 0 0 0 0 0 0 0

  ]a =: 2 0 set a
2 0 0 0 0 0 0 0

NB.  defining this was the whole point of my feeble efforts
inc =: 4 : '((>:(x. get y.))(x.) set y.)'
dec =: 4 : '((<:(x. get y.))(x.) set y.)'

NB. above gives an error
     inc =: 4 : '( 1&+(x. get y.)),( x.) set y.'
  dec =: 4 : '(_1&+(x. get y.)),( x.) set y.'
  a
2 0 0 0 0 0 0 0
  ]a =: 0 inc a
1 0 0 0 0 0 0 0 0

NB. OK, it puts the 1:  at the 0th position... but adds a zero

inc =: 4 : '( 1&+(x. get y.)),( x.) set y.'
dec =: 4 : '(_1&+(x. get y.)),( x.) set y.'
a =: b
  a
0 0 0 0 0 0 0 0
  ]a =: 0 inc a
1 0 0 0 0 0 0 0 0
  ]a =: 0 inc a
2 0 0 0 0 0 0 0 0 0
  ]a =: 0 inc a
3 0 0 0 0 0 0 0 0 0 0

NB. in this case, incrementing works but the array lengthens...

Admittedly, trying to do this may be just plain foolish, but what's the REAL way to do this?

Thanks,

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