Pattern matching: Difference between revisions

Content deleted Content added
mNo edit summary
adding a reference
Line 91:
will match elements such as A[1], A[2], or more generally A[''x''] where ''x'' is any entity. In this case, <code>A</code> is the concrete element, while <code>_</code> denotes the piece of tree that can be varied. A symbol prepended to <code>_</code> binds the match to that variable name while a symbol appended to <code>_</code> restricts the matches to nodes of that symbol. Note that even blanks themselves are internally represented as <code>Blank[]</code> for <code>_</code> and <code>Blank[x]</code> for <code>_x</code>.
 
The Mathematica function <code>Cases</code> filters elements of the first argument that match the pattern in the second argument:<ref>{{Cite web|title=Cases—Wolfram Language Documentation|url=https://reference.wolfram.com/language/ref/Cases.html.en|access-date=2020-11-17|website=reference.wolfram.com}}</ref>
<syntaxhighlight lang="mathematica">
Cases[{a[1], b[1], a[2], b[2]}, a[_] ]