/ GENTLE PRIMER
/ Special Patterns and Expressions
Sometimes one wishes to process the constituents of a pattern, but also the pattern as a whole. We can use the where predicate to inspect the term, as in
'rule' HandleSignal(S): where (S -> signal(C1, C2)) ProcessSignal(S) ProcessColor(C1) ProcessColor(C2)Alternatively, we can prefix a pattern with a variable name (followed by a colon). This is equivalent to the unprefixed pattern but if matching succeeds, then the named variable is defined as if the pattern had simply been the variable name.
Thus, the above rule could also be written:
'rule' HandleSignal(S : signal(C1, C2)): ProcessSignal(S) ProcessColor(C1) ProcessColor(C2)