On Thu, Sep 18, 2008 at 5:42 AM, Rob Hodgkinson <[EMAIL PROTECTED]> wrote:
> An alternative is also the approach to 'add infinity where 0 = temp') ...
>
> rplc0byInf =: [ + _&* @ (0&=)
>
> rplc0byInf temp
> 5 7 _ _ _
> 3 6 _ 5 4
>
> But this doesn't address your general Amend / Tacit query like Ric's
> solution...
But it can.
We only need Amend because J does not support concepts of 0 and 1
with +, - and * in the context of literal and boxed data.
Here's a somewhat specialized example:
]t=:2 5 ?.10
4 3 0 0 0
4 3 6 2 9
27 rplc0byx t
4 3 27 27 27
4 3 6 2 9
Here's a more general example:
rplc=: 0&{::
inds=: 1&{::
data=: 2&{::
deltaa=: rplc - data {~ <"[EMAIL PROTECTED]
deltab=: [EMAIL PROTECTED]@data e. [EMAIL PROTECTED] #. inds
delta=: deltab ([EMAIL PROTECTED] $ ,@[ expand ]) deltaa
modify=: (data + delta) f.
]exdata=: ?.2 3 6$10
4 6 8 6 5 8
6 6 6 9 3 2
3 1 9 2 7 0
9 5 7 7 9 7
4 8 7 4 2 1
1 0 4 3 9 3
]exinds=: ($ #: I.@,) 1 = exdata
0 2 1
1 1 5
1 2 0
]exrplc=: 1000+i.#exinds
1000 1001 1002
modify exrplc;exinds;exdata
4 6 8 6 5 8
6 6 6 9 3 2
3 1000 9 2 7 0
9 5 7 7 9 7
4 8 7 4 2 1001
1002 0 4 3 9 3
modify
2&({::) + ([EMAIL PROTECTED]@(2&({::)) e. $@(2&({::)) #. 1&({::)) ([EMAIL
PROTECTED] $ ,@[ #^:_1
]) 0&({::) - 2&({::) {~ <"1@(1&({::))
(If you are really interested in this approach you should also examine
the results of the
other verbs I defined, against the example argument I supplied for modify).
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm