%%家庭关系%%
%定义父亲
father("Bill","John").
father("Pam","Bill").
%查询Bill是谁的父亲
%father(X,"Bill")
%查询Bill的父亲是谁
%father("Bill",X)
%定义爷爷
grandFather(Person,GrandFather):-
father(Person,Father),
father(Father,GrandFather).
%谁的爷爷是Bill?
%grandFather(X,"Bill")
%Pam的爷爷是谁?
%grandFather("Pam",X)
%定义双亲
parent(Person,Parent) :-
mother(Person,Parent);
father(Person,Parent).
%定义兄弟姐妹
sibling(Person,Slibling) :-
mother(Person,Mother),Mother(Sibling,Mother).
sibling(Person,Sibling) :-
father(Person,Father),father(Sibling,Father).
%亲兄弟姐妹
fullBlodedSibling(Person,Sibling):-
mother(Person,Mother),
mother(Sibling,Mother),
father(Person,Father),
father(Sibling,Father).
mother("Bill","Lisa").
father("Bill","John").
father("Pam","Bill").
father("Jack","Bill").
parent(Person,Parent):-
mother(Person,Mother);
father(Person,Father).
%查找如下三个人
/*
?-father(AA,BB),parent(BB,CC).
(1)查找符合父子关系的(AA,BB)
(2)对步骤(1)中的查询结构,查找符合双亲
关系的(BB,CC)
*/
阅读(1271) | 评论(0) | 转发(0) |