Previous Up Next

5.5  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 in the clause head:

p(f(X)) :-
    -?->
    q(X).

Using the ?- operator in the neck of the clause (instead of :-) is an alternative way of expressing the same, so the following is equivalent to the above:

p(f(X)) ?-
    q(X).

Matching clauses are not supported in dynamic clauses. A runtime error (calling an undefined procedure -?->/1) will be raised when executing dynamic code that has a matching clause head.

Pattern matching can be used for several purposes:


Previous Up Next