Pascal, good day Can you amend 3 with 300 with you adverbs in the next? ]box=:1;2;<3;4 ┌─┬─┬─────┐ │1│2│┌─┬─┐│ │ │ ││3│4││ │ │ │└─┴─┘│ └─┴─┴─────┘
thanks On Tue, Sep 24, 2013 at 2:44 AM, Pascal Jasmin <[email protected]>wrote: > very nice, thank you. > > Its not quite the same, as the explicit version allows for a select verb > like picking out the rows where column 2 is prime > > (0 _2:amdt 2 +:amdt ])"1 amend (I.@:(1&p:)@:(2&{"1)) i. 5 5 > _2 1 4 3 4 > _2 6 14 8 9 > 10 11 12 13 14 > _2 16 34 18 19 > 20 21 22 23 24 > > though a workaround is faster for large data: > (I.@:(1&p:)@:(2&{"1) a) (0 _2:amdt 2 +:amdt ])"1 amdt a=. i. 5 5 > > > > I can't seem to get the L:0 version working though: > > amdtL0 =. ((((@:{(L:0)))((`[)(`])))}(L:0)) > > compared to: > > > amendL0_z_ =: 2 : 0 NB. v is n or n{"num > s=. v"_ y > (u (s{ L:0 y)) (s}) L:0 y > ) > > replace all 4 columns for rows 0-3 > (i.4) (0;1;2;'f')"1 amdt amendL0 (i.3) (<"1 &. |: i. 5 3), <'ABCDE' > ┌──────────┬───────────┬───────────┬─────┐ > │0 0 0 9 12│1 1 1 10 13│2 2 2 11 14│fffDE│ > └──────────┴───────────┴───────────┴─────┘ > > rearrange columns for rows 2 and 3 > ((<'f') ,~ |.@:}:)"1 amendL0 2 3 (<"1 &. |: i. 5 3), <'ABCDE' > ┌───────────┬───────────┬──────────┬─────┐ > │0 3 8 11 12│1 4 7 10 13│2 5 6 9 14│ABffE│ > └───────────┴───────────┴──────────┴─────┘ > > > ----- Original Message ----- > From: June Kim (김창준) <[email protected]> > To: Programming forum <[email protected]> > Cc: > Sent: Monday, September 23, 2013 1:22:32 PM > Subject: Re: [Jprogramming] A useful amend conjunction > > I think someone might be interested in a tacit version. > > > amdt=.((@:{)((`[)(`])))} > 3 (0 _2: amdt 2 _1: amdt ]) amdt i. 5 5 > 0 1 2 3 4 > 5 6 7 8 9 > 10 11 12 13 14 > _2 16 _1 18 19 > 20 21 22 23 24 > > 3 4 5 ((-&32)&.(a.&i.)) amdt 'abcdefgh' > abcDEFgh > > > > On Sun, Sep 22, 2013 at 8:48 AM, Pascal Jasmin <[email protected] > >wrote: > > > Here is what seems to me a much easier/saner version of amend to use, > > especially for chained amends. 2 versions, one called for L:0 y, then > > other without. The dyad version doesn't seem totally necessary. > > > > amend_z_ =: 2 : 0 NB. v is n or n{"num > > if. 0 = 4!:0 <'v' do. s =. v else. s =. v y end. > > (u (s{y)) (s}) y > > : > > if. 0 = 4!:0 <'v' do. s =. v else. s =. v y end. > > (x u (s{y)) (s}) y > > ) > > > > amendL0_z_ =: 2 : 0 NB. v is n or n{"num > > if. 0 = 4!:0 <'v' do. s =. v else. s =. v y end. > > (u (s{ L:0 y)) (s}) L:0 y > > : > > if. 0 = 4!:0 <'v' do. s =. v else. s =. v y end. > > (x u (s{ L:0)y) (s} L:0) y > > ) > > > > ([: 2: amend 0 3: amend 1) amend 2 ( i. 5 3) NB. replace in row 2, > col > > 0 and 1 > > 0 1 2 > > 3 4 5 > > 2 3 8 > > 9 10 11 > > 12 13 14 > > ([: 2: amend 0 3: amend 1) amend 2 &.|: ( i. 5 3) NB. replace in col > > 2, row 0 and 1 > > 0 1 2 > > 3 4 3 > > 6 7 8 > > 9 10 11 > > 12 13 14 > > > > > > ((0;'f')"_ amend 1 3) amendL0 3 (<"1 &. |: i. 5 3), <'ABCDE' NB. > for > > row 3, replace col 1 and 3 > > ┌──────────┬──────────┬───────────┬─────┐ > > │0 3 6 9 12│1 4 7 0 13│2 5 8 11 14│ABCfE│ > > └──────────┴──────────┴───────────┴─────┘ > > > > ( 2&+ L:0 amend 1 2) amendL0 3 4 (<"1 &. |: i. 5 3), <'ABCDE' NB. > > use function y, to replace col 1 and 2 of row 3 and 4 > > ┌──────────┬───────────┬───────────┬─────┐ > > │0 3 6 9 12│1 4 7 12 15│2 5 8 13 16│ABCDE│ > > └──────────┴───────────┴───────────┴─────┘ > > > > > > or dyad: > > > > 2( + L:0 amend 1 2) amendL0 3 4 (<"1 &. |: i. 5 3), <'ABCDE' > > ┌──────────┬───────────┬───────────┬─────┐ > > │0 3 6 9 12│1 4 7 12 15│2 5 8 13 16│ABCDE│ > > └──────────┴───────────┴───────────┴─────┘ > > > > more complex function: change row 3 from 9;10;11;'D' to 11;10;9;'f' > > > > ((<'f') ,~ |.@:}:) amendL0 3 (<"1 &. |: i. 5 3), <'ABCDE' > > ┌───────────┬───────────┬──────────┬─────┐ > > │0 3 6 11 12│1 4 7 10 13│2 5 8 9 14│ABCfE│ > > └───────────┴───────────┴──────────┴─────┘ > > > > > > for improvements, the v side could be a 2 sided gerund for the {`} sides > > which could be for example {"1`}"1 or {L:0`}L:0 > > > > > > Thank you Raul and Aai for your help. > > > > > > ----- Original Message ----- > > From: Raul Miller <[email protected]> > > To: Programming forum <[email protected]> > > Cc: > > Sent: Saturday, September 21, 2013 12:50:48 AM > > Subject: Re: [Jprogramming] Amend trickiness part 2 > > > > On Fri, Sep 20, 2013 at 6:21 PM, Pascal Jasmin <[email protected]> > > wrote: > > >> I wanted to use the dyadic definition, but did not have > > >> a meaningful value for x, so I used ~ (giving the effect of y m} y). > > > > > > There seems to be a lot more going on there. There is already an x > > value of 1. > > > > Here? > > > > 1 3:`2:`]}~&.>@{`[`]} <"1 |: i. 5 3 > > > > In this case, the ~ in the phrase 3:`2:`]}~&.>@... appears in the verb > > which is on the left side of an @ > > > > And we always use the monadic definition of the verb on the left of the @ > > > > So we use the monadic definition of 3:`2:`]}~&.> and so we use the > > monadic definition of 3:`2:`]}~ > > > > (And the tilde means we use the dyadic definition of 3:`2:`]}) > > > > That said, I should point out that there's something subtle going on > > here, with word boundaries: > > > > ;:'1 2 3: 4 5' > > +---+--+---+ > > |1 2|3:|4 5| > > +---+--+---+ > > > > > for instance with the value x of _3 _2 0 or 2, an answer is provided, > > > but item 1 of the middle cell is also modified. Other values of x > > > give various domain or index errors. If the '~' is removed, then x > > > values of 0 to 2, produce a middle cell of 6 to 8. I can't follow > > > what causes those results at all. > > > > The x that I think you are speaking of here is relevant for the verb > > on the right hand side of the @ so lets simplify the left hand side > > and play with the expression a bit: > > > > 1 <@0:@{`[`]} <"1 |: i. 5 3 > > +----------+-+-----------+ > > |0 3 6 9 12|0|2 5 8 11 14| > > +----------+-+-----------+ > > _3 _2 0 <@0:@{`[`]} <"1 |: i. 5 3 > > +-+-+-----------+ > > |0|0|2 5 8 11 14| > > +-+-+-----------+ > > 2 <@0:@{`[`]} <"1 |: i. 5 3 > > +----------+-----------+-+ > > |0 3 6 9 12|1 4 7 10 13|0| > > +----------+-----------+-+ > > > > Note also that index _3 is (for this argument) the same as index 0. > > > > > Next I'm trying to change columns 1 and 4 row 2 to 3 and 'F', but I > > expect that to be harder. > > > > Well... I'm not quite sure what you want there, but let us assume that > > you want to change > > > > (<"1 &. |: i. 5 3), <'ABCDE' > > +----------+-----------+-----------+-----+ > > |0 3 6 9 12|1 4 7 10 13|2 5 8 11 14|ABCDE| > > +----------+-----------+-----------+-----+ > > > > to > > > > +----------+-----------+-----------+-----+ > > |0 3 3 9 12|1 4 7 10 13|2 5 8 11 14|ABFDE| > > +----------+-----------+-----------+-----+ > > > > if so, a phrase that would accomplish that would be: > > > > (3;7;8;'F') [`2:`]}&.> data > > > > Here, I've presumed that you are calling the contents of a box a > > "column" and that you are calling the location within a box a "row". > > I've also presumed that you have added 1 to the "column index" when > > you are speaking of "columns 1 and 4". I could easily be wrong, > > though, about your intentions. If so, let us know and we can try > > again? > > > > Thanks, > > > > -- > > Raul > > ---------------------------------------------------------------------- > > 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 > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
