Previous Up Next

4.6  Matching

In ECLiPSe you can write clauses that use matching (or one-way unification) instead of head unification. Such clauses are written with the ?- functor instead of :-. Matching has the property that no variables in the caller will be bound. For example

p(f(a,X)) ?- writeln(X).

will fail for the following calls:

?- p(F).
?- p(f(A,B)).
?- p(f(A,b)).

and succeed (printing b) for

?- p(f(a,b)).

Moreover, the clause

q(X,X) ?- true.

will fail for the calls

?- q(a,b).
?- q(a,B).
?- q(A,b).
?- q(A,B).

and succeed for

?- q(a,a).
?- q(A,A).

Previous Up Next