before implementing Kip's version, here is a useful though hacky conjunction I
call filtermod.
The v side produces a filter (list of 1s and 0s), the u side takes as argument
the list selected by the filter and just needs to return the same number of
items. It may modify and even reorder the items. After u is done, the new
items in new order will be inserted back into the list at the filtered indexes.
filtermod =: 2 : 0 NB. v is filter func, u is func that modifies items. then
modified items replaced in original.
if. isNoun 'u' do. '`box mod' =. u else. '`box mod' =. ]`u end.
a =. v y
> a} box y,: a # inv mod a # y
:
if. isNoun 'u' do. '`box mod' =. u else. '`box mod' =. ]`u end.
a =. x v y
> a} box y,: a # inv x mod a # y
)
u can optionally be a gerund, though its a bit hacky, it may be more flexible
than Kip's solution. The typical gerund addition would be <"1, but it can be
any verb necessary to provide amend with a conforming shape.
for rows that total over 6, slide the tail element into the next pair:
<"1`({."1,. _1 |. {:"1) filtermod ((6 < +/"1)) i. 6 2
0 1
2 3
4 11
6 5
8 7
10 9
simpler ones:
2 (5&+) filtermod < i. 6
NB. ^: trick
0 1 2 13 14 15
2 (5 + ]) filtermod < i. 6 NB. add 5 to items greater than 2
0 1 2 8 9 10
2 (2|. 5 + ]) filtermod < i. 6 NB. and reordered.
0 1 2 10 8 9
----- Original Message -----
From: Kip Murray <[email protected]>
To: "[email protected]" <[email protected]>
Cc:
Sent: Friday, July 11, 2014 11:09:10 PM
Subject: Re: [Jprogramming] speaking of amend...
v =: (-. , ])@[ # ,/@]
0 1 1 v i. 2 3 2
0 1
8 9
10 11
On Friday, July 11, 2014, Linda Alvord <[email protected]> wrote:
> I made it too hard because I thought I had seen carriage returns.
>
> f=: 13 :'(x}i.2 3){((*/0 1{$y),2)$,y'
> f
> 4 : '(x}i.2 3){((*/0 1{$y),2)$,y'
> 0 1 1 f i.2 3 2
> 0 1
> 8 9
> 10 11
>
> Linda
>
> -----Original Message-----
> From: [email protected] <javascript:;>
> [mailto:[email protected] <javascript:;>] On
> Behalf Of Linda Alvord
> Sent: Friday, July 11, 2014 10:53 PM
> To: [email protected] <javascript:;>
> Subject: Re: [Jprogramming] speaking of amend...
>
> I'm sure I'll learn lots of better ways than this.
>
> f=: 13 :'3 1 2$,(x}i.2 3){((*/0 1{$y),2)$,y'
> f
> 4 : '3 1 2$,(x}i.2 3){((*/0 1{$y),2)$,y'
>
> 0 1 1 f i.2 3 2
> 0 1
>
> 8 9
>
> 10 11
>
> Linda
>
> -----Original Message-----
> From: [email protected] <javascript:;>
> [mailto:[email protected] <javascript:;>] On
> Behalf Of 'Pascal
> Jasmin' via Programming
> Sent: Friday, July 11, 2014 8:57 PM
> To: Programming forum
> Subject: [Jprogramming] speaking of amend...
>
> what verb v (or I guess adverb is ok) could I use to get
>
> 0 1 1 v i. 2 3 2
>
> 0 1
> 8 9
> 10 11
>
>
> i.2 3 2
> 0 1
> 2 3
> 4 5
> 6 7
> 8 9
> 10 11
> ----------------------------------------------------------------------
> 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
>
--
Sent from Gmail Mobile
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm