- The use of Dispatch will never affect results that are obtained, but may make the application of long lists of rules much faster.
- Lists of rules are usually scanned sequentially when you evaluate an expression like expr/.rules. Rules such as a->a1 and a->a2, which cannot simultaneously apply, need not both be scanned explicitly. Dispatch generates a dispatch table which uses hash codes to specify which sets of rules need actually be scanned for a particular input expression.
- Lists of rules produced by assignments made with = and := are automatically optimized with dispatch tables when appropriate.
- Dispatch is treated as a raw object by functions like AtomQ and for purposes of pattern matching.
- Normal converts a Dispatch to a list of rules.
Examplesopen allclose all
Basic Examples (2)
Dispatch may be much faster for a long list of rules:
Use Dispatch with pattern-based rules:
Introduced in 1991