WolframLang: Pattern Matching
Pattern matching is a core mechanism how WolframLang does computation. WolframLang is a term-rewriting system, meaning, it transform expressions according to rules until no rule matches.
A rule is a pair of values that looks like this:
left-hand-side → right-hand-side
The left-hand-side is a pattern (which includes literal expression). The right-hand-side is replacement, which may include parts of the captured pattern.
For the transformation, there are local and global transformations:
- Local transformation: Functions that take a expression and list of rules, and return a new expression.
- Global transformation: A set a rules defined globally. Evaluation of any expression uses these rules to transform expression.
- For local transformation: WolframLang: Rule, RuleDelayed
- For global transformation: WolframLang: Set, SetDelayed