Previous Contents Next
6.18 Logic, control and exceptions

6.18.1 abort/0, stop/0, top_level/0, break/0, halt/1, halt/0

Templates

abort
stop
top_level
break
halt(+integer)
halt
Description

abort aborts the current execution. If this execution was initiated under a top-level the control is given back to the top-level and the message {execution aborted} is displayed. Otherwise, e.g. execution started by a initialization/1 directive (section 5.1.13), abort/0 is equivalent to halt(1) (see below).

stop stops the current execution. If this execution was initiated under a top-level the control is given back to the top-level. Otherwise, stop/0 is equivalent to halt(0) (see below).

top_level starts a new recursive top-level (including the banner display). To end this new top-level simply type the end-of-file key sequence (Ctl-D) or its term representation: end_of_file.

break invokes a recursive top-level (no banner is displayed). To end this new level simply type the end-of-file key sequence (Ctl-D) or its term representation: end_of_file.

halt(Status) causes the GNU Prolog process to immediately exit back to the shell with the return code Status.

halt is equivalent to halt(0).

Errors

Status is a variable    instantiation_error
Status is neither a variable nor an integer    type_error(integer, Status)

Portability

halt/1 and halt/0 are ISO predicates. abort/0, stop/0, top_level/0 and break/0 are GNU Prolog predicates.

6.18.2 once/1, (\+)/1 - not provable, call_with_args/1-11, call/2

Templates

once(+callable_term)
\+(+callable_term)
call_with_args(+atom, +term,..., +term)
call(+callable_term, ?boolean)
Description

once(Goal) succeeds if call(Goal) succeeds. However once/1 is not re-executable on backtracking since all alternatives of Goal are cut. once(Goal) is equivalent to call(Goal), !.

\+ Goal succeeds if call(Goal) fails and fails otherwise. This built-in predicate gives negation by failure.

call_with_args(Functor, Arg1,..., ArgN) calls the goal whose functor is Functor and whose arguments are Arg1,..., ArgN (0 £ N £ 10).

call(Goal, Deterministic) succeeds if call(Goal) succeeds and unifies Deterministic with true if Goal has not created any choice-points, with false otherwise.

\+ is a predefined prefix operator (section 6.14.10).

Errors

Goal is a variable    instantiation_error
Goal is neither a variable nor a callable term    type_error(callable, Goal)
The predicate indicator Pred of Goal does not correspond to an existing procedure and the value of the unknown Prolog flag is error (section 6.22.1)    existence_error(procedure, Pred)
Functor is a variable    instantiation_error
Functor is neither a variable nor an atom    type_error(atom, Functor)
Deterministic is neither a variable nor a boolean    type_error(boolean, Deterministic)

Portability

once/1 and (\+)/1 are ISO predicates, call_with_args/1-11 and call/2 are GNU Prolog predicates.

6.18.3 repeat/0

Templates

repeat
Description

repeat generates an infinite sequence of backtracking choices. The purpose is to repeatedly perform some action on elements which are somehow generated, e.g. by reading them from a stream, until some test becomes true. Repeat loops cannot contribute to the logic of the program. They are only meaningful if the action involves side-effects. The only reason for using repeat loops instead of a more natural tail-recursive formulation is efficiency: when the test fails back, the Prolog engine immediately reclaims any working storage consumed since the call to repeat/0.

Errors

None.

Portability

ISO predicate.

6.18.4 for/3

Templates

for(?integer, +integer, +integer)
Description

for(Counter, Lower, Upper) generates an sequence of backtracking choices instantiating Counter to the values Lower, Lower+1,..., Upper.

Errors

Counter is neither a variable nor an integer    type_error(integer, Counter)
Lower is a variable    instantiation_error
Lower is neither a variable nor an integer    type_error(integer, Lower)
Upper is a variable    instantiation_error
Upper is neither a variable nor an integer    type_error(integer, Upper)

Portability

GNU Prolog predicate.


Copyright (C) 1999,2000 Daniel Diaz

Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.

More about the copyright
Previous Contents Next