Next: Meta-Call Predicates
Up: Built-In Predicates
Previous: Standard Order of
The predicates of this section implement control structures. Normally
these constructs are translated into virtual machine instructions by
the compiler. It is still necessary to implement these constructs
as true predicates to support meta-calls, as demonstrated in the
example below. The predicate finds all currently defined atoms of 1
character long. Note that the cut has no effect when called via one
of these predicates (see !/0).
one_character_atoms(As) :-
findall(A, (current_atom(A), atom_length(A, 1)), As).
- fail
Always fail. The predicate fail/0 is translated into a single virtual
machine instruction.
- true
Always succeed. The predicate true/0 is translated into a single virtual
machine instruction.
- repeat
Always succeed, provide an infinite number of choice points.
- !
Cut. Discard choice points of parent frame and frames created after the
parent frame. Note that the control structures ;/2, |/2
->/2 and /1 are normally handled by the compiler and do
not create a frame, which implies the cut operates through these
predicates. Some examples are given below. Note the difference between
t3/1 and t4/1. Also note the effect of call/1 in t5/0. As the argument
of call/1 is evaluated by predicates rather than the compiler the cut
has no effect.

- +Goal1 , +Goal2
Conjunction. Succeeds if both `Goal1' and `Goal2' can be proved. It is
defined as (this definition does not lead to a loop as the second comma
is handled by the compiler):
Goal1, Goal2 :- Goal1, Goal2.
- +Goal1 ; +Goal2
The `or' predicate is defined as:
Goal1 ; _Goal2 :- Goal1.
_Goal1 ; Goal2 :- Goal2.
-
- +Goal1
|
+Goal2
Equivalent to ;/2
. Retained for compatibility only. New code
should use ;/2
. Still nice though for grammar rules.
-
- +Condition
->
+Action
If-then and If-Then-Else. Implemented as:
If -> Then; _Else :- If, !, Then.
If -> _Then; Else :- !, Else.
If -> Then :- If, !, Then.
-
-
\+
+Goal
Succeeds if `Goal' cannot be proven (mnemnonic: + refers to provable
and the backslash is normally used to indicate negation).
Next: Meta-Call Predicates
Up: Built-In Predicates
Previous: Standard Order of
Passani Luca
Tue Nov 14 08:58:33 MET 1995