4.2.3 Control Structures

As we have seen, the goals in the body of a sentence are linked by the operator ‘,’, which can be interpreted as conjunction (and). The Prolog language provides a number of other operators, known as control structures, for building complex goals. Apart from being built-in predicates, these control structures play a special role in certain language features, namely Grammar Rules (see ref-gru), and when code is loaded or asserted in the context of modules (see ref-mod). The set of control structures is described in this section, and consists of:

:P,:Q ISO
prove P and Q
:P;:Q ISO
prove P or Q
+M::P ISO
call P in module M
:P->:Q;:R ISO
if P succeeds, prove Q; if not, prove R
:P->:Q ISO
if P succeeds, prove Q; if not, fail
! ISO
cut any choices taken in the current procedure
\+ :P ISO
goal P is not provable
?X ^ :P
there exists an X such that P is provable (used in setof/3 and bagof/3)
+Iterators do :Body
executes Body iteratively according to Iterators
if(:P,:Q,:R)
for each solution of P succeeds, prove Q; if none, prove R
once(:P) ISO
Find the first solution, if any, of goal P.

Send feedback on this subject.