4,494
edits
m (Text replacement - "</source>" to "</syntaxhighlight>") |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
Line 4: | Line 4: | ||
Match can be used to compare [[simple]] [[vector]]s to see if they are the same: | Match can be used to compare [[simple]] [[vector]]s to see if they are the same: | ||
< | <syntaxhighlight lang=apl> | ||
1 2 3 ≡ 1 2 3 | 1 2 3 ≡ 1 2 3 | ||
1 | 1 | ||
Line 11: | Line 11: | ||
</syntaxhighlight> | </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: | ||
< | <syntaxhighlight lang=apl> | ||
(1 2)3 ≡ (2 1)3 | (1 2)3 ≡ (2 1)3 | ||
0 | 0 | ||
</syntaxhighlight> | </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. | ||
< | <syntaxhighlight lang=apl> | ||
(3 2⍴⍳6) ≡ (2 3⍴⍳6) | (3 2⍴⍳6) ≡ (2 3⍴⍳6) | ||
0 | 0 | ||
Line 23: | Line 23: | ||
</syntaxhighlight> | </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: | ||
< | <syntaxhighlight lang=apl> | ||
a←⎕CT+b←2 3 4 ⍝ Two vectors | a←⎕CT+b←2 3 4 ⍝ Two vectors | ||
a - b ⍝ Difference is not zero | a - b ⍝ Difference is not zero | ||
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]] (< | The following model implements Match in [[Dyalog APL]]. Because Match compares the same characteristic of both arguments, [[Over]] (<syntaxhighlight lang=apl inline>⍥</syntaxhighlight>) is used throughout. | ||
< | <syntaxhighlight lang=apl> | ||
Match ← { | Match ← { | ||
⍺≠⍥(≢⍴)⍵: 0 ⍝ Rank | ⍺≠⍥(≢⍴)⍵: 0 ⍝ Rank | ||
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 < | * J [https://www.jsoftware.com/help/dictionary/d122.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/minusco#dyadic NuVoc] (as <syntaxhighlight lang=j inline>-:</syntaxhighlight>) | ||
== See also == | == See also == |