| Did you know ... | Search Documentation: |
| Predicate behaviour and determinism |
The keywords in table 4 may appear in the manual's predicate descriptions and in pldoc structured comments in source code. They describe the general behaviour of a predicate.
det | A deterministic predicate always succeeds exactly once and does not leave a choicepoint. |
semidet | A semi-deterministic predicate succeeds at most once. If it succeeds, it does not leave a choicepoint. |
nondet | A non-deterministic predicate is the most general case and no claims are made on the number of solutions (which may be zero, i.e., the predicate may fail) and whether or not the predicate leaves a choicepoint on its last solution. |
multi | As nondet, but succeeds
at least once. |
failure | Always fails. |
undefined | Well-founded semantics “third value” . See undefined/0. |
“Leaving no choicepoint” means that the system knows that redoing the predicate will not yield any additional solutions. For example, member/2 is non-deterministic, but deterministic if the solution is the last element of the list. The predicate member/2 may not know immediately whether there are more solutions after the first one, so a choicepoint remains, even if it eventually turns out to yield nothing:
?- member(1, [2,1,3]). true ; % there may be more solutions false. % actually not
If a solution is the last element of the list, there is enough information to leave no choicepoint:
?- member(1, [2,3,1]). true.
Note that if the toplevel waits for input after a query this
indicates that the query succeeded with a choicepoint. If the user
enters the toplevel explains the location of
the choicepoint. Alternatively, the GUI debugger may be used to examine
the open choicepoints.
*