This subject regularly pops up every now and then, and it reminds me of 
something I wrote a little while back that might interest you. I found a couple 
of errors in them (oops) so I’m copying them here in hope that they are of help 
to you. They aren’t pretty or succinct but they work. (Code at bottom.)

These are versions of the composition conjunctions which depend on their right 
operand verb’s rank (that is, @, &, and &.), that take as left operand a 
gerund, and apply successive verbs in the gerund to the successive results of 
applying its right operand to successive cells of its right argument (or 
between its left and right arguments). The gerund is extended cyclically.

The above sentence being far too long for comprehension, an example imposes 
itself:
   M=: i.3 4 5
   (,: -`j. under >) ;/M
┌───────────────────┬────────────────────────┬───────────────────┐ │ 0 1 2 3 4 
│20 21 22 23 24 │40 41 42 43 44 │ │ 5 6 7 8 9 │25 26 27 28 29 │45 46 47 48 49 │ 
│10 11 12 13 14 │30 31 32 33 34 │50 51 52 53 54 │ │15 16 17 18 19 │35 36 37 38 
39 │55 56 57 58 59 │ 
├───────────────────┼────────────────────────┼───────────────────┤ │ 0 _1 _2 _3 
_4│0j20 0j21 0j22 0j23 0j24│_40 _41 _42 _43 _44│ │ _5 _6 _7 _8 _9│0j25 0j26 
0j27 0j28 0j29│_45 _46 _47 _48 _49│ │_10 _11 _12 _13 _14│0j30 0j31 0j32 0j33 
0j34│_50 _51 _52 _53 _54│ │_15 _16 _17 _18 _19│0j35 0j36 0j37 0j38 0j39│_55 _56 
_57 _58 _59│ └───────────────────┴────────────────────────┴───────────────────┘

What you’re looking for is probably rank:

   >:`<:`+:`-: rank 0 i.4
1 0 4 1.5
   >:`<:`+:`-: rank 1 i.4 3
  1  2   3
  2  3   4
 12 14  16
4.5  5 5.5
   1 +`- rank 0 1 ] i.2 3
 1  2  3
_2 _3 _4

Cheers,
Louis

Code:

temp=: 2 : 0    NB. utility
        [: (v^:_1@(4 : 'y`:6  >x')"0 m $~ $) <@v
)

NB. @
atop=: 2 : 'm temp (v :. ])'

NB. &.
under=: 2 : 0
        m temp v : ([: (v^:_1@(4 : 'y`:6&>/>x')"0 m $~ $) <@,&<&v)
)

NB. &
compose=: 2 : 'm under (v :. ])'

NB. "
rank=:  2 : 'm compose (]"n)'
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to