next up previous index
Next: Soft Cut Up: ECLiPSe-specific Language Features Previous: The String Data Type   Index


Matching Clauses

When Prolog systems look for clauses that match a given call, they use full unification of the goal with the clause head (but usually without the occur check). Sometimes it is useful or necessary to use pattern matching instead of full unification, i.e. during the matching only variables in the clause head can be bound, the call variables must not be changed. This means that the call must be an instance of the clause head.

The operator -?-> at the beginning of the clause body specifies that one-way matching should be used instead of full unification:

p(f(X)) :-
    -?->
    q(X).
Pattern matching can be used for several purposes:

If some argument positions of a matching clause are declared as output in a mode declaration, then they are not unified using pattern matching but normal unification, in this case then the variable is normally bound. The above example can thus be also written as

:- mode get_attr(?, -).
get_attr(X{A}, A) :-
    -?->
    true.
but in this case it must not be called with its second argument already instantiated.


next up previous index
Next: Soft Cut Up: ECLiPSe-specific Language Features Previous: The String Data Type   Index
Warwick Harvey
2004-08-07