0
votes

I am running into a wall while writing prolog using the YAP prolog. I isolated my problem to these two lines of code:

is_a(G, A2):-is_a(G, A1), is_a_link(A1, A2).
is_a(x, y).

If I put these two lines of code in a file, and consult the file, en ask prolog if is_a(x,y), the program never ends, leading me to believe there's an infinite loop involved.

But I don't understand why there would be a loop, I just asked prolog whether one of its axioms is true, shouldn't it (without a second thought) simply spit out Yes?

I mean, as far as I understand the way prolog works, it will try to find a true statement in the knowledge base that "proves" the statement. I am confused about why it does not simply return the axiom.


EDIT:

Switching the lines of code, i.e.

is_a(x, y).
is_a(G, A2):-is_a(G, A1), is_a_link(A1, A2).

makes the prolog not crash, since it obviously first encounters the true statement.

1
How is is_a_link/2 implemented? Even though you swapped the fact with the predicate, it will still not terminate. It just happens to produce the x and y solution infinitely instead of just once. - lurker

1 Answers

0
votes

Rename your fact to something else:

is_a_fact_or_whatever(x,y).
is_as(G,A2) :- is_a_fact_or_whatever(G,A1), is_a_link(A1,A2).