Match: Difference between revisions

Jump to navigation Jump to search
63 bytes added ,  22:13, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 9: Line 9:
       1 2 3 ≡ 1 2 5
       1 2 3 ≡ 1 2 5
0
0
</source>
</syntaxhighlight>
Using [[strand notation]] to create [[nested]] arrays, we see that Match also compares elements nested within arrays:
Using [[strand notation]] to create [[nested]] arrays, we see that Match also compares elements nested within arrays:
<source lang=apl>
<source lang=apl>
       (1 2)3 ≡ (2 1)3
       (1 2)3 ≡ (2 1)3
0
0
</source>
</syntaxhighlight>
Arrays with the same elements but different shapes do not match. Unlike [[Equal to]], Match never gives a [[RANK ERROR]] or [[LENGTH ERROR]] because of argument shapes.
Arrays with the same elements but different shapes do not match. Unlike [[Equal to]], Match never gives a [[RANK ERROR]] or [[LENGTH ERROR]] because of argument shapes.
<source lang=apl>
<source lang=apl>
Line 21: Line 21:
       'a' ≡ ,'a'  ⍝ Scalar versus singleton
       'a' ≡ ,'a'  ⍝ Scalar versus singleton
0
0
</source>
</syntaxhighlight>
Match depends on [[comparison tolerance]]. Here two arrays which are not exactly identical are still reported as matching:
Match depends on [[comparison tolerance]]. Here two arrays which are not exactly identical are still reported as matching:
<source lang=apl>
<source lang=apl>
Line 31: Line 31:
       a {⎕CT←0⋄⍺≡⍵} b  ⍝ ...but not intolerantly
       a {⎕CT←0⋄⍺≡⍵} b  ⍝ ...but not intolerantly
0
0
</source>
</syntaxhighlight>


== Description ==
== Description ==
Line 43: Line 43:
=== APL model ===
=== APL model ===


The following model implements Match in [[Dyalog APL]]. Because Match compares the same characteristic of both arguments, [[Over]] (<source lang=apl inline>⍥</source>) is used throughout.
The following model implements Match in [[Dyalog APL]]. Because Match compares the same characteristic of both arguments, [[Over]] (<source lang=apl inline>⍥</syntaxhighlight>) is used throughout.
<source lang=apl>
<source lang=apl>
Match ← {
Match ← {
Line 52: Line 52:
   ⍺∧.∇⍥,⍵        ⍝ Recurse
   ⍺∧.∇⍥,⍵        ⍝ Recurse
}
}
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL 18.0]]}}
{{Works in|[[Dyalog APL 18.0]]}}


Line 64: Line 64:
* [http://microapl.com/apl_help/ch_020_020_360.htm APLX]
* [http://microapl.com/apl_help/ch_020_020_360.htm APLX]
* [https://mlochbaum.github.io/BQN/doc/match.html BQN]
* [https://mlochbaum.github.io/BQN/doc/match.html BQN]
* J [https://www.jsoftware.com/help/dictionary/d122.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/minusco#dyadic NuVoc] (as <source lang=j inline>-:</source>)
* J [https://www.jsoftware.com/help/dictionary/d122.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/minusco#dyadic NuVoc] (as <source lang=j inline>-:</syntaxhighlight>)


== See also ==
== See also ==

Navigation menu