Here is circular part of my facts (define relation between people):
connection(harry, ron).
connection(ron, harry).
connection(hermione, harry).
I want to find out if there is a connection, either directly or through other people using recursion.
This code runs into an infinite loop in the above situation:
connected(A, B) :-
connection(A, B).
connected(A, B) :-
connection(A, C),
connected(C, B).
I want the recursion to stop when it encounters previous searches. For example:
?- connected(hermione, X).
X = harry ;
X = ron.
Thank you!