left fn ##.rank{ranks}    right ⍝ Apply function to/between rank-⍵⍵ sub-arrays.
left fn ##.rank ranks {⍵} right
     fn ##.rank{ranks}    right
     fn ##.rank ranks {⍵} right

Supplied by Phil Last, who says: "This pretty much follows Iverson's definition.
The  right  operand  is used in such a way that the value(s) for monadic, left &
right ranks can be placed in braces or to the left of a convenient identity."

I'm not sure that negative ranks are treated correctly. It does something but it
may not be what Iverson (or I) intended!

Technical notes:

Notice  Phil's  technique  of  allowing  the right operand of rank to be a ranks
_vector_  or _function_. For example, either (1 2) or {1 2}. In either case, the
ranks are extracted by the expression ⍵⍵,⍬ in the following:

        g←⌽3⍴⌽⍵⍵,⍬
              ¯¯¯¯
This  (constant  function) device is handy in Dyalog, as the binding of adjacent
arrays  is  stronger than the binding of an operator to its operand _array_. For
example,  if  [op] is a dyadic operator, and if [rand] is the operator's _array_
operand and [rarg] is the derived function's array argument, then:

        land op rand rarg <≡≡> land op (rand rarg)

        land op {rand} rarg <≡≡> (land op {rand}) rarg

        land op rand {⍵} rarg <≡≡> (land op rand) {⍵} rarg

Notice  also  the  technique  of  determining whether the (derived) function was
called in a monadic or dyadic context (left argument missing or present).

        m←0 ⋄ ⍺←m←1

The second phrase ⍺←m←1 is evaluated only if the function is called with no left
argument.  An alternative coding, which is possible since the enhancement to the
interpreter  (2001-05-31)  to  allow  '⍺',  '⍵', '⍺⍺', '⍵⍵' as arguments to ⎕NC,
would be:

        m←0=⎕nc'⍺'

Examples:

      (2 2⍴1 2 2 1)⍉rank{1 2}2 3 4⍴⍳99      ⍝ (using ranks _function_)
 1  2  3  4
 5  6  7  8
 9 10 11 12
 0  0  0  0

13 17 21  0
14 18 22  0
15 19 23  0
16 20 24  0

      (2 2⍴1 2 2 1)⍉rank 1 2 +2 3 4⍴⍳99     ⍝ (using ranks _vector_)
 1  2  3  4
 5  6  7  8
 9 10 11 12
 0  0  0  0

13 17 21  0
14 18 22  0
15 19 23  0
16 20 24  0

Back to: contents

Back to: Workspaces

Trouble seeing APL font?