I have the typical relationship example.
m(thomas).
m(leon).
w(nina).
born(thomas, nina, leon).
born(Father, Mother, Child) :- born(Mother, Father, Child).
father(Father, Child) :- born(Father, Mother, Child), m(Father).
mother(Mother, Child) :- born(Father, Mother, Child), w(Mother).
parent(Parent, Child) :- (father(Parent, Child); mother(Parent, Child)).
When I ask after parent, only the father will be listed:
?- parent(X, leon).
X = thomas ;
X = thomas ;
.....
I want both parents:
?- parent(X, leon).
X = thomas ;
X = nina ;
What can I do?
Edit: problem:
My problem wasn't the or because it normally gives back both statements.
The problem was that born/3, in the code above, is a loop.
I tried to make the mother and father exchange able against each other.
Edit: fix:
I got two answers on this from ChristianF and CapelliC. They both helped me to understand the what was wrong with my statement.
My own solution:
m(thomas).
m(leon).
w(nina).
b(thomas, nina, leon).
born(Father, Mother, Child)
:- (m(Father), w(Mother), b(Father, Mother, Child)); b(Mother, Father, Child).
father(Father, Child) :- born(Father,_, Child), m(Father).
mother(Mother, Child) :- born(_, Mother, Child), w(Mother).
parent(Parent, Child) :- (father(Parent, Child); mother(Parent, Child)).
born(Father, Mother, Child) :- born(Mother, Father, Child).is a lot of trouble. One thing that would help is to establish a convention forborn/3facts in which the father or the mother is always listed first. - lurker