paths ← item ##.in array                    ⍝ Locations of item ⍺ in array ⍵.

[in] returns a vector of the "pick-paths" of the locations of [item] in [array].
Each item of the result is a vector, which can be used to select the [item] from
the [array] using primitive function pick (⊃).

Examples:

    1 in 3 1 4 1 5                              ⍝ vector of path vectors
┌─┬─┐
│2│4│
└─┴─┘

    'o' in 'hello' 'world'                      ⍝ locations of 'o' characters
┌───┬───┐
│1 5│2 2│
└───┴───┘
    'o'{'⌽' @(⍺ in ⍵)⊢⍵} 'hello' 'world'        ⍝ substitution
┌─────┬─────┐
│hell⌽│w⌽rld│
└─────┴─────┘

    'o'in ⍪'hello' 'world'                      ⍝ paths in matrix ⍵
┌───────┬───────┐
│┌───┬─┐│┌───┬─┐│
││1 1│5│││2 1│2││
│└───┴─┘│└───┴─┘│
└───────┴───────┘

    avg←(sum←+⌿)÷≢                              ⍝ functions for sum and average

    ⎕cr'avg'                                    ⍝ character rep.
┌──┬─┬─┐
│+⌿│÷│≢│
└──┴─┴─┘
    (⊂'sum')@((⎕CR'sum')in ⎕CR'avg')⊢⎕CR'avg'   ⍝ name instead of value
┌───┬─┬─┐
│sum│÷│≢│
└───┴─┴─┘

Back to: contents

Back to: Workspaces