Availability:built-in
det
(deterministic).
As a result, both failure and success with a choicepoint is considered
an error. The behaviour if the declaration is violated is controlled
with the Prolog flag determinism_error.
The default is to raise an exception (error
). Consider the
following program:
:- det(p/1). p(1). p(2).
Now, a call ?- p(1).
behaves normally. However:
?- p(X). ERROR: Deterministic procedure p/1 succeeded with a choicepoint ERROR: In: ERROR: [10] p(1) ?- p(a). ERROR: Deterministic procedure p/1 failed ERROR: In: ERROR: [10] p(a)
Violations throw an error/2 exception
determinism_error(Pred, Declared, Observed, property)
.
The trap/1 (cli) or gtrap/1 (gui) predicate can be used to make the debugger stop near the error. For example:
?- gtrap(determinism_error(_,_,_,_)).