between_1_and_3(X, Y), integer(X) => between(1, X, Y).
I just noticed that if the body is non deterministic, then there are again choice points. For some reason i thought that the clause would leave no choice points – for the clause committed to.
So, its up to the developer to a) ensure that the guard does not instantiate the variables in the head, in particular not the output variables, and b) that the body is determinant, and c) to provide mutual exclusive and exhaustive guard cases, to obtain the benefit of a determinant and steadfast predicate.
So, what exactly is the added value of =>, beside avoiding the need to include a cut, after the guard.
Is it the added runtime checks and raised exception for a non-complete case analysis provided by guards?
Of course, there is added value by the => construct to make the developers intent explicit.
edit:
Why does this fail?
between_1_and_3(X, Y), between(1,2, X) => X=2, between(1, X, Y).
I guess, because, the guard gets committed to the first solution – i guess this clarifies why we don’t want the guard to instantiate a head variable, since the declarative reading here seems to make no sense.
Does it make sense to require for => all input variables, i.e. those mentioned in guards, to be ground? Although, the below, wouldn’t fit – but, declaring X a var effectively means its an output variable.
between_1_and_3(X, Y), var(X) => X=1, between(1, X, Y).
Edit:
comparing the below, the runtime checks become more apparent, with the first raising an exception and the second (t(X)) simply failing, when called unbound.
between_1_and_3(X, Y), integer(X) => X=1, between(1, X, Y).
t(X) :-
integer(X),
X=1.
Dan