It was suggested to move this question here for further discussion. this
Copied by EricGT from StackOverflow
So my question is basically the oppsite of this.
I have some code, something like this:
even(X) :- 0 is mod(X, 2). odd_number(X) :- not(even(X)). odd_number(X) :- write(X).
Is there any reason why, upon failing the first predicate, not to try the second function?
Although my code is more complicated, I will not show it because it is a homework. I just want to know if there would be any reason why upon returning false from the first predicate, the program doesn’t redo the function, but with the second predicate.
Note: The pattern matching stuff is not the problem. I am 100% sure my function matches at least one pattern written after the predicate which fails.
Details for better understanding of my issue:
This is how a tracing works on this program:
Call:odd_number(6) Call:not(even(6)) Fail:not('10892dd7-de05-49c0-8057-1d7684c4ae68' : even(6)) Redo:odd_number(6) Call:write(6) 6 Exit:write(6) Exit:odd_number(6) true
This is how the tracing looks in my program:
Call:odd_number(6) Call:not(even(6)) Fail:not('10892dd7-de05-49c0-8057-1d7684c4ae68' : even(6)) *Calls some weird function completely unrelated to this predicate*