family(
person(jim, tan, male, hobby([fishing, badminton, swim]), dob(2, 1, 1962)),
person(ann, tan, female, hobby([cooking, badminton]), dob(4,9, 1968)),
[person(ham, tan, male, hobby([fishing, football, swim]), dob(18,5, 1984)),
person(wan, tan, female, hobby([reading, music, swim]), dob(25, 12, 1986))]
). % Tan's Family(Husband, Wife, [Life_of_Children]).
family(
person(john, lim, male, hobby([music, reading, watchingTV]), dob(28, 10, 1972)),
person(belle, lim, female, hobby([music, reading, badminton]), dob(9, 4, 1974)),
[person(sophia, lim, female, hobby([reading, traveling]), dob(8, 8, 1985)),
person(annie, lim, female, hobby([badminton, volleyball, games]), dob(9, 6, 1987)),
person(william, lim, male, hobby([badminton, swim, games]), dob(10, 7, 1988))]
).
% Lim's Family
husband(X):- %X is a husband if
family(X, _, _). %X is the 1st member in family
wife(X):- %X is a wife if
family(_, X, _). %X is a 2nd member in family
child(X):- %X is a child if
family(_, _, ChildList), %X is a member in ChildList
member(X, ChildList).
family_member(X):- % X is a family member if
husband(X); % X is a husband, or
wife(X); % X is a wife, or
child(X). % X is a child.
gender(Person, X):- % The gender of Person is X if
Person = person(_, _, X, _,_). % X matched with the 3rd element in person
interest(Person, X):- % Interest of Person is X if
Person = person(_, _, _, hobby(HobbyList),_),
member(X, HobbyList). % X is a member in HobbyList.
firstname(X, FirstName):-
X = person(FirstName, _, _, _, _).
lastname(X, LastName):-
X = person(_, LastName, _, _, _).
birthday(X, dob(Day, Month, Year)):-
X = person(_, _, _, _, dob(Day, Month, Year)).
yob(X, Year):-
X = person(_, _, _, _, dob(_, _, Year)).
father(Father, Child).
brother(Child1, Child2):-
child(_),
lastname(Child1, LastName1),
lastname(Child2, LastName2),
LastName1 = LastName2.
我如何检查兄弟/2 Child1 和 Child2 来自同一个家庭?我不认为我的是正确的。以及如何在 SWI-Prolog 中显示以查找来自所有家庭的所有兄弟?我将非常感谢您的帮助:)