Gentle
Applications
Concepts
Examples
Handbook
Support
Download

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

f ( P_{1} , ... , P_{n} )
the matching succeeds if Tau has
the form
f ( Tau_{1} , ... , Tau_{n} )
and matching
Tau_{1}, ..., Tau_{n}
against
P_{1}, ..., P_{n}
succeeds, thereby defining the variables appearing in
P_{1}, ..., P_{n}.
Otherwise, the matching fails.
If P appears on a position with type T,
the declaration of T must contain a functor specification
f ( T_{1} , ... , T_{n} ).
P_{1}, ..., P_{n}
appear on positions with types
T_{1}, ..., T_{n}.



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( Tau_{1} ,list(yellow,
Tau_{2} )).
It defines X1 as a variable of type Color
with value Tau_{1}
and X2 as a variable of type List
with value Tau_{2}.
Otherwise, the matching fails.



Named Patterns
If P has the form
Tau is matched against P_{1} as if the pattern P
had been simply P_{1}.
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.
[NEXT] [PREV]
