I'm doing a very simple exercise in Prolog and there's something I don't understand in the trace. The program is a "greater than" (>
) on integers represented as successors:
greater_than(succ(_), 0).
greater_than(succ(A), succ(B)) :-
greater_than(A, B).
My problem: I don't understand why the request greater_than(succ(succ(succ(0))),succ(0))
generates a redo
in the following trace:
[trace] ?- greater_than(succ(succ(succ(0))),succ(0)).
Call: (6) greater_than(succ(succ(succ(0))), succ(0)) ? creep
Call: (7) greater_than(succ(succ(0)), 0) ? creep
Exit: (7) greater_than(succ(succ(0)), 0) ? creep
Exit: (6) greater_than(succ(succ(succ(0))), succ(0)) ? creep
true ;
Redo: (7) greater_than(succ(succ(0)), 0) ? creep
Fail: (7) greater_than(succ(succ(0)), 0) ? creep
Fail: (6) greater_than(succ(succ(succ(0))), succ(0)) ? creep
false.
Why is there a redo
here? How can I avoid it (without a cut, of course)?
BTW, before you ask : no, it's not some kind of homework...