Difference between revisions of "Membership"
Line 54:  Line 54:  
</source>{{Works in[[Dyalog APL]], [[NARS2000]], [[dzaima/APL]], [[Extended Dyalog APL]], [[GNU APL]]}}  </source>{{Works in[[Dyalog APL]], [[NARS2000]], [[dzaima/APL]], [[Extended Dyalog APL]], [[GNU APL]]}}  
+  == See also ==  
+  * [[Equal to]]  
+  * [[Match]]  
+  * [[Find]]  
+  * [[Index of]]  
== External links ==  == External links ==  
Revision as of 10:20, 9 July 2020
∊

Membership (∊
), also called Member Of or Member In, is a dyadic primitive function which tests if each of the elements of the left argument appears as an element of the right argument. Membership derives from the traditional mathematical notation (Element of) and therefore uses that glyph (lunate epsilon).
Examples
Both arguments can be arrays of any shape. Each element of the left argument is tested against elements of the right argument, and the result is a boolean array having the same shape as the left argument.
'THIS NOUN'∊'THAT WORD'
1 1 0 0 1 0 1 0 0
3 6 9∊3 3⍴⍳9
1 1 1
(3 3⍴⍳9)∊3 6 9
0 0 1
0 0 1
0 0 1
For nested arrays, Membership tests for exact match between the elements.
'CAT' 'DOG' 'MOUSE' ∊ 'CAT' 'FOX' 'DOG' 'LLAMA'
1 1 0
Leading axis model
The behavior of Membership was changed to follow leading axis model in some implementations such as J (spelled e.
). In this case, if the right argument is a higherrank array, the cells of the left argument with appropriate rank are compared against the major cells of the right argument.
]mat=.>'able';'acre';'idle'
able
acre
idle
'able' e. mat
1
(<'able') e. mat
0
'ab' e. mat
0
(3 3 4$'able') e. mat NB. the resulting shape is trailing axes (corresponding to the major cells of mat) removed
1 1 1
1 1 1
1 1 1
In other dialects, a leading axis membership function can be defined as:
Membership←{(≢⍵)≥⍵⍳⍺}
⎕←mat←3 4⍴'ableacreidle'
able
acre
idle
'able' Membership mat
1
See also
External links
Documentation