Tutorial by Examples

Prolog tries alternative clauses for a predicate in the order of appearance: likes(alice, music). likes(bob, hiking). // Either alice likes music, or bob likes hiking will succeed. The disjunction (OR) operator ; can be used to express this in one rule: likes(P,Q) :- ( P = alice , Q = ...
Conjunction (logical AND) is represented by the comma , operator (among other roles). Conjunction between clauses can appear in a query: ?- X = 1, Y = 2. Conjunction can also appear between the subgoal clauses in the body of a rule: triangleSides(X,Y,Z) :- X + Y > Z, X + Z > Y, Y + ...
Sometimes it is desirable to prevent Prolog from backtracking into alternative solutions. The basic tool available to the programmer to stop prolog from continuing futher in its backtrack is the cut operator. consider the following. % (percent signs mean comments) % a is the parent of b, c, and d....

Page 1 of 1