4.7 Control Predicates
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Control Predicates
          • fail/0
          • false/0
          • true/0
          • repeat/0
          • !/0
          • ,/2
          • ;/2
          • |/2
          • ->/2
          • *->/2
          • \+/1
    • Packages
Availability:built-in
Source[ISO]:Goal1 ; :Goal2
Disjunction (or). True if either Goal1 or Goal2 succeeds. Note that the semantics change if Goal1 contains ->/2 or *->/2. ;/2 is transparent to cuts. See !/0 for details. For example:
?- (between(1,2,X) ; X = a).
X = 1 ;
X = 2 ;
X = a.

It is strongly advised to always use parenthesis around disjunctions. Conjunctions inside a disjunction should not use parenthesis. Traditionally the ; is placed at the start of the line rather than at the end because a ; at the end of a line is easily overlooked. Below is an example of the preferred style used in SWI-Prolog.75Some users prefer a newline after the ;.

p :-
    a,
    (   b,
        c
    ;   d
    ).

Although ;/2 is a control structure that is normally handled by the compiler, SWI-Prolog implements ;/2 as a true predicate to support call/2 and friends as well as to allow for querying predicate properties, for example to support code analysis.