
HANDBOOK
/ LANGUAGE REFERENCE MANUAL
/
Patterns
Pattern =
IdentUC [":" Pattern]
|
Functor
["("[Pattern{ "," Pattern}]")"]
|
"_" .
A given value Tau may be matched against a pattern P.
This may succeed, thereby defining the variables appearing
in P, or fail.
Variables
If P has the form
where V is a variable,
the value of V is defined as Tau and the type of V is the type of the
position.
Terms
If P has the form
the matching succeeds if Tau has
the form
f ( Tau1 , ... , Taun )
and matching
Tau1, ..., Taun
against
P1, ..., Pn
succeeds, thereby defining the variables appearing in
P1, ..., Pn.
Otherwise, the matching fails.
If P appears on a position with type T,
the declaration of T must contain a functor specification
f ( T1 , ... , Tn ).
P1, ..., Pn
appear on positions with types
T1, ..., Tn.
|
|
|
Example
list(X1, list(yellow, X2))
If a value Tau is matched against this pattern (on a position of
type List), the matching succeeds if
Tau has the form list( Tau1 ,list(yellow,
Tau2 )).
It defines X1 as a variable of type Color
with value Tau1
and X2 as a variable of type List
with value Tau2.
Otherwise, the matching fails.
|
|
|
Named Patterns
If P has the form
Tau is matched against P1 as if the pattern P
had been simply P1.
If this succeeds,
V is defined as if the pattern P had been simply V.
Joker
If P has the form
(underscore) the matching always succeeds.
