look at 'Item Amend': </} 1 2 3,:2 2 2 2 2 3
R.E. Boss (Add your info to http://www.jsoftware.com/jwiki/Community/Demographics ) > -----Original Message----- > From: [email protected] [mailto:programming- > [email protected]] On Behalf Of Raul Miller > Sent: maandag 7 juli 2014 12:33 > To: [email protected] > Subject: Re: [Jprogramming] Tacit J and indexed replacement > > 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, > > -- > Raul > > On 7/7/14, Erling Hellenäs <[email protected]> wrote: > > Hi all ! > > > > About the problem I want to solve. > > > > Generally you compare some arrays and you want to replace part of one of > > them with info from the other or from some other array of the same > > dimensions? > > > > I found a solution not using Amend: > > > > 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 > > > > 1 2 3(< {"0 1 [ ,"0 ])2 2 2 > > 2 2 3 > > > > > > A similar solution using Amend. I'm sure it can be improved, just I > > didn't do it yet. I didn't try it for the general case. > > > > > > NB. Amend > > > > NB. x (v0`v1`v2)} y ↔ (x v0 y) (x v1 y)} (x v2 y) > > > > 1 2 3(> # [)`(> # [: i. [: $ ])`(])}2 2 2 > > 2 2 3 > > > > > > I think what makes Amend tricky is that you(as Ric says) need three > > inputs. To get them into the tacit expression you have to put two of > > them together in one noun. > > > > > > There are probably other solutions using sort. > > > > > > Trying the same expression with a version of Raul's Amend: > > > > amende=: (0 {:: [)`(1 {:: [)`]} > > > > 1 2 3((> (# ; [: (# i.&$) [ ) [) amende ])2 2 2 > > > > 2 2 3 > > > > > > Some bug causes Thunderbird to reformat my mails. Hope you get them > right. > > > > I'm looking for something more general than this :) > > > > 1 2 3 >. 2 2 2 > > > > 2 2 3 > > > > > > /Erling > > > > On 2014-07-07 05:58, Raul Miller wrote: > >> Since it'w nagging at me (and this is still unteted code :/), here's > >> what I currently think i should have said: > >> amend=: (0:{::])`(1:{::])`(2:{::])}~ > >> > >> The trailing ~ because I need the dyad from the resulting verb, and > >> the trailing ] on each because those verbs need to ignore one of the > >> resulting arguments. > >> > >> Sadly, my fingers (and "quick memory") keep forgetting this. > >> > >> 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
