Section "control"

The Dogelog player provides already correct handling of a conjunction and disjunction of goals in a Prolog clause body or in a Prolog query. This also extends to the cut. The conjunction and disjunction do not have a direct built-in since they are translated into internals. In particular the cut is mapped to '$CUT'/1 with an additional argument.

Example:

?- (X=1;X=2), !.
X = 1.

The interpreter has the capability to interrupt its control flow by exception handling. An interruption happens when an exception is thrown or when a signal is raised. An exception can be an arbitrary Prolog term. Some exception terms are recognized by the interpreter so as to display a user-friendly stack trace. In particular we recognize:

error(_, _)
warning(_, _)
cause(_, _)

The predicate throw/1 can be used to throw an exception. If the context is a variable the predi-cate will automatically instantiate the variable with the current stack trace. The predicate catch/1 can be used to catch a thrown exception. The predicate will only catch non-urgent exceptions and match the head of a chained exception.

The following control built-ins are provided:

true: [ISO 7.8.1]
The predicate succeeds.
A; B: [ISO 7.8.6]
The predicate succeeds whenever A or B succeed.
A -> B: [ISO 7.8.7]
The predicate succeeds when A succeeds and then whenever B succeed.
A, B: [ISO 7.8.5]
The predicate succeeds whenever A and B succeed.
!: [ISO 7.8.4]
The predicate removes choice points created in the current clause.
fail: [ISO 7.8.2]
The built-in fails.
catch(G, E, F): [ISO 7.8.9]
The built-in succeeds whenever G succeeds. If there was a non-urgent exception that unifies with E, the built-in further succeeds whenever F succeeds.
throw(E): [ISO 7.8.9]
The predicate possibly fills the stack trace and then raises the exception B.

Kommentare