Prolog Language Control structures Disjunction (logical OR), implicit vs. explict


Example

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 = music ) ; ( P = bob , Q = hiking ).

Parentheses are important here for clarity. See this Question on relative precedence for conjunction , and disjunction ;.