I am doing a very simple exercise in Prolog, and there is something I don’t understand in the trace. The program is "more than" ( > ) for integers represented as successors:
greater_than(succ(_), 0). greater_than(succ(A), succ(B)) :- greater_than(A, B).
My problem: I do not understand why the request greater_than(succ(succ(succ(0))),succ(0)) generates 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 redo here? How can I avoid this (without cutting, of course)?
By the way, before asking: no, this is not some kind of homework ...
source share