The predicates of this section implement control structures. Normally the constructs in this section, except for repeat/0, are translated by the compiler. Please note that complex goals passed as arguments to meta-predicates such as findall/3 below cause the goal to be compiled to a temporary location before execution. It is faster to define a sub-predicate (i.e. one_character_atoms/1 in the example below) and make a call to this simple predicate.
one_character_atoms(As) :- findall(A, (current_atom(A), atom_length(A, 1)), As).
t0 :- (a, !, b). | % prunes a/0 and t0/0 |
t1 :- (a, !, fail ; b). | % prunes a/0 and t1/0 |
t2 :- (a -> b, ! ; c). | % prunes b/0 and t2/0 |
t3 :- call((a, !, fail ; b)). | % prunes a/0 |
t4 :- | % prunes a/0 |
Goal1, Goal2 :- Goal1, Goal2.
Goal1 ; _Goal2 :- Goal1. _Goal1 ; Goal2 :- Goal2.
If -> Then; _Else :- If, !, Then. If -> _Then; Else :- !, Else. If -> Then :- If, !, Then.
Please note that (If ->
Then) acts as (If ->
Then ;
fail), making the construct fail if the condition fails.
This unusual semantics is part of the ISO and all de-facto Prolog
standards.
\+
Condition, Else).
In other words, if
Condition succeeds at least once, simply behave as the
conjunction of Condition and Action, otherwise
execute Else.
The construct A *->
B, i.e. without
an
Else branch, is translated as the normal conjunction A,
B.bugThe decompiler
implemented by clause/2
returns this construct as a normal conjunction too.
+
refers to provable and the backslash (\
)
is normally used to indicate negation in Prolog).