You are describing item amend, which may be turned into a verb as follows:

ia =: 4 : 'x} y'

   1 1 0 ia 2 2 2 ,:~ 1 2 3 
2 2 3

   1 1 0 ([ ia 2 2 2 ,:~ ]) 1 2 3 
2 2 3 



________________________________
From: Erling Hellenäs <[email protected]>
To: [email protected] 
Sent: Monday, July 7, 2014 1:53:52 PM
Subject: Re: [Jprogramming] Tacit J and indexed replacement


It's obviously not possible to do any amendments in tacit code? It is 
also less elegant to pass these three parameters in the two arguments in 
tacit code? Any opinions about the use of From to do the same thing?

NB. x and y are arrays of the same rank
NB. q is a boolean, also of this rank
NB. The expression merges x and y.
NB. Where q is TRUE it picks from y, otherwise x
NB. q {"0 1 x,"0 y

If q is a vector and if we actually have a variable z of rank (+/q),}.$y 
we can easily create x from q#^:_1 [ z ? No use for any indexes?

/Erling




On 2014-07-07 12:33, Raul Miller wrote:
> Another approach for this is:
>     (x*-.q)+y*q
>
> Sadly, that only works when x and y are numeric. Boxes and literals do
> not have zero and 1 values (hypothetically "fill" could be zero, but
> "1" is harder to rationalize.)
>
> A variant which uses amend might be:
>     (q#y) (I.q)} x
>
> This only works when x and y are rank 1, but you could also use
> something like this for higher ranked arrays:
>     ($q)$ (q#&,y) (I.,q)} ,x
>
> (I hope I didn't make too many mistakes this time. I'm running without
> any corrective support.)
>
> Thanks,
>

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