Membership: Difference between revisions
Jump to navigation
Jump to search
m (Text replacement - "</source>" to "</syntaxhighlight>") Tags: Mobile edit Mobile web edit |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
Line 5: | Line 5: | ||
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. | 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. | ||
< | <syntaxhighlight lang=apl> | ||
'THIS NOUN'∊'THAT WORD' | 'THIS NOUN'∊'THAT WORD' | ||
1 1 0 0 1 0 1 0 0 | 1 1 0 0 1 0 1 0 0 | ||
Line 18: | Line 18: | ||
For [[nested array|nested arrays]], Membership tests for exact [[match]] between the elements. | For [[nested array|nested arrays]], Membership tests for exact [[match]] between the elements. | ||
< | <syntaxhighlight lang=apl> | ||
'CAT' 'DOG' 'MOUSE' ∊ 'CAT' 'FOX' 'DOG' 'LLAMA' | 'CAT' 'DOG' 'MOUSE' ∊ 'CAT' 'FOX' 'DOG' 'LLAMA' | ||
1 1 0 | 1 1 0 | ||
Line 25: | Line 25: | ||
=== Leading axis model === | === Leading axis model === | ||
The behavior of Membership was changed to follow [[leading axis model]] in some implementations such as [[J]] (spelled < | The behavior of Membership was changed to follow [[leading axis model]] in some implementations such as [[J]] (spelled <syntaxhighlight lang=j inline>e.</syntaxhighlight>). In this case, if the right argument is a higher-[[rank]] array, the [[cell|cells]] of the left argument with appropriate rank are compared against the [[major cell|major cells]] of the right argument. | ||
< | <syntaxhighlight lang=j> | ||
]mat=.>'able';'acre';'idle' | ]mat=.>'able';'acre';'idle' | ||
able | able | ||
Line 44: | Line 44: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
In other dialects, a leading axis membership function can be defined as: | In other dialects, a leading axis membership function can be defined as: | ||
< | <syntaxhighlight lang=apl> | ||
Membership←{(≢⍵)≥⍵⍳⍺} | Membership←{(≢⍵)≥⍵⍳⍺} | ||
⎕←mat←3 4⍴'ableacreidle' | ⎕←mat←3 4⍴'ableacreidle' |