I can’t seem to wrap my head around this. Consider the following dummy predicate:
foo(X, a) :- X < 10.
foo(X, b) :- X > 20.
When consulting:
?- foo(1, a).
true;
false.
I am not sure I completely understand how the choice point is created anyway (Perhaps because the two possible foo predicates are in a kind of or relationship and Prolog just tries to unify with both? Based on this line in the trace: Redo: (24) test:foo(8, a) and the subsequent fail, I suppose this is the case), but what really confuses me is why it works when the argument order is changed:
foo(a, X) :- X < 10.
foo(b, X) :- X > 20.
?- foo(a, 1).
true.
No choice point. What am I missing here?
bcan never be a good match, and skips it. - Willem Van OnsemXcould match,bstill doesn’t? - bp99findall(found, foo(1,a), All)spits out a single solution,[found], it's good. Add a "!" or a "-"> to make the Prolog processor "commit" to its clause after the guard test:foo(X) :- guard(X),!,do_sth(X).or (maybe clearer)foo(X) :- guard(X) -> do_sth(X).to increase determinacy while making sure the solutions collected byfindall/3stay constant. - David Tonhoferfoo(1, a), !.when I am already cutting? And thank you both, can one of you please create an answer as well so I can select it as the solution? - bp99