Pattern matching: Difference between revisions

Content deleted Content added
a 1970 pattern matcher in Lisp is pretty late and not notable; fix chronology -- why was QED before COMIT??
Tags: Mobile edit Mobile web edit Advanced mobile edit
Line 95:
==Pattern matching in Mathematica==
In [[Mathematica]], the only structure that exists is the [[Tree (data structure)|tree]], which is populated by symbols. In the [[Haskell (programming language)|Haskell]] syntax used thus far, this could be defined as
<syntaxhighlight lang="mathematicahaskell">
data SymbolTree = Symbol String [SymbolTree]
</syntaxhighlight>
An example tree could then look like
<syntaxhighlight lang="mathematica">
Symbol "a" [Symbol "b" [], Symbol "c" [] ]
</syntaxhighlight>
In the traditional, more suitable syntax, the symbols are written as they are and the levels of the tree are represented using <code>[]</code>, so that for instance <code>a[b,c]</code> is a tree with a as the parent, and b and c as the children.
 
A pattern in Mathematica involves putting "_" at positions in that tree. For instance, the pattern