I have a few facts:
parent(bob, anne). % bob is a. parent of anne.
sibling(anne, mary).
I'm trying to get parents from sibling facts, so if I query parent(X, mary)
bob should be an output. So far my rules are:
siblingOf(X,Y) :- sibling(X,Y).
siblingOf(X,Y) :- sibling(Y,X).
parent(X,Z) :-
siblingOf(Z,Y),
parent(X,Y).
It goes on an infinite loop. I suspect it is because the recursive call has no end condition. What can I do to make it work?
parent/2
is both a fact aboutbob
andanne
and also a rule that recursively callsparent/2
.parent(bob, X)
can thus re-enterparent/2
with the same variables. Rename the rule to something else, likeparentOf/2
the way you did withsiblingOf/2
instead ofsibling/2
and you may have better luck. – Daniel Lyonsparent(X, mary)
– Juan Dela CruzparentOf(X, mary)
, if you followed my advice above. – Daniel LyonsparentOf
. I will try tinkering more with it, keeping your advice in mind. – Juan Dela Cruz