I struggle with a rather simple GNU Prolog example:
I have a file (test.pl)
cat(muki).
dog(roti).
frog(frogi).
animal(X) :- dog(X).
animal(X) :- cat(X).
When testing it:
- Importing via
['test.pl'] animal(frogi)returnsno, as expectedanimal(muki)returnsyes, as expectedanimal(roti)returnstrue ?instead ofyes, which is not what I would expect.
As far as I know this means that prolog is capable to solve animal for roti but why it does not return yes, just like before?
Compare with
trace/0Ok, now swap the two
animal/1predicates and trace againOn the second run you can see that a failure was encountered and GNU Prolog had to backtrack. If there is no backtracking and the query is true straightaway, with no alternatives to backtrack through, GNU Prolog will show
true. If there is backtracking and ultimately the query succeeds, and there exist alternative paths to backtrack though, then GNU Prolog will showyesand allow you to enter a;to show other solutions. In this case if you were to enter a semi-colon to show other solutions the only other solution is a failure (try it out!)