Skip to content

Index R←X⌷Y

X must be a scalar or vector of depth ≤2 of integers each ≥⎕IO. Y may be any array. In general, the result R is similar to that obtained by square-bracket indexing in that:

      (I J ...  Y)  Y[I;J;...]

The length of left argument X must be less than or equal to the rank of right argument Y. Any missing trailing items of X default to the index vector of the corresponding axis of Y.

Note that in common with square-bracket indexing, items of the left argument X may be of any rank and that the shape of the result is the concatenation of the shapes of the items of the left argument:

      (XY)  ↑,/¨X

Index is sometimes referred to as squad indexing.

Note that index may be used with selective specification.

⎕IO is an implicit argument of index.

Examples

      ⎕IO1

      VEC111 222 333 444
      3VEC
333
      (4 3)VEC
444 333
      (2 33 1 4 1 2 3)VEC
333 111 444
111 222 333

      MAT10¨3 4
11 12 13 14
21 22 23 24
31 32 33 34

      2 1MAT
21
      2MAT
21 22 23 24
      3(2 1)MAT
32 31
      (2 3)1MAT
21 31
      (2 3)(,1)MAT
21
31
      (2 11)(3 42)MAT
2 1 3 4
       MAT
0 0
      (3(2 1)MAT)0  MAT    ⍝ Selective assignment.
11 12 13 14
21 22 23 24
 0  0 33 34

Indexing Classes

If Y is a ref to an instance of a Class with a Default property, is applied to the Default property. Similarly, applied to a COM or .NET collection returns the appropriate item(s) of the collection.

Example

      ⎕SRC c
:Class c                 
    :Property Default p  
    :Access Public Shared
         rget          
          r2 3 4⎕A     
                        
    :EndProperty         
:EndClass                

      2c
MNOP
QRST
UVWX