We want to instrument our Prolog code by automatic determinism
checks. So in the spirit of Ciao assertions we would declare
:- pred <functor>/<arity> is <determinism>
, where <determinism>
can take the values:
Value | Description |
---|---|
det | have exactly one solution, then that mode is deterministic |
semidet | either have no solutions or have one solution, then that mode is semideterministic |
multi | have at least one solution but may have more, then that mode is multisolution |
nondet | have zero or more solutions, then that mode is nondeterministic |
https://www.mercurylang.org/information/doc-latest/mercury_ref/Determinism-categories.html
Here is an example expected behaviour, take this Prolog text input:
:- pred r/1 is multi.
r(b).
r(c).
r(c).
And then this query output:
?- r(a).
Error: Unknown pattern: assertion_failure(multi)
?- r(b).
Yes
?- r(c).
Yes ;
Yes
Since most Prolog systems have term expansion and goal expansion, it seems to be a suitable language to inject such assertions at compile time by some Prolog code itself. How would one go about and implement such an instrumentation?