Index Of
From NARS2000
Jump to navigationJump to search


L is an array of rank not equal 1.  
R is an arbitrary array.  
Z is a nested array of shape ⍴R whose items are each integer vectors of length ⍴⍴L, suitable for use as indices to L, except for where the item in R is not found in L, in which case the corresponding item in Z is ⎕IO+⍴L.  
This feature extends dyadic iota to nonvector left arguments.  
This function is sensitive to ⎕IO and ⎕CT. 
For example, in origin1
M←2 3⍴'abcdef'
M⍳'afg'
1 1 2 3 3 4
M[M⍳'af']
af
L←2 ⋄ ⎕fmt L⍳⍳3
┌3──────────┐
│┌0┐ ┌0┐ ┌0┐│
││0│ │0│ │0││
│└~┘ └~┘ └~┘2
└∊──────────┘
Note that this extension preserves the identity R≡L[L⍳R] for all R⊆L.
This extension is implemented via an internal magic function:
∇ Z←L #DydIota R;⎕IO;O
[1] O←⎕IO ⋄ ⎕IO←0
[2] Z←⊂[0] O+(1+⍴L)⊤(¯1↓,(1+⍴L)↑L)⍳R
∇