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