You have already seen how to represent alternative ways of satisfying a particular goal by giving more than one clause which could match that goal. For example, we could write a program to decide whether or not any number was between two other numbers using the following two clauses:
between(N, N1, N2):- N > N1, N < N2. between(N, N1, N2):- N < N1, N > N2.
This program states that
N is between two numbers
N2 if either
N is greater than
N is less than
is greater than
N2. This could be stated more succinctly using the
special disjunction operator,
`;', which is often interpreted in
English as "or".
between(N, N1, N2):- (N > N1, N < N2) ; (N < N1, N > N2).
The brackets round the conjunction of inequalities on each side of
the disjunction operator aren't really necessary. We have included
them to emphasise the nested structure of the term.
This new definition of
between/3 using the
is identical in meaning to the original definition using two separate clauses.