Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1720293
  • 博文数量: 171
  • 博客积分: 11553
  • 博客等级: 上将
  • 技术积分: 3986
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-25 20:28
文章分类

全部博文(171)

文章存档

2012年(2)

2011年(70)

2010年(9)

2009年(14)

2008年(76)

分类:

2008-08-25 00:07:23

%%家庭关系%%
%定义父亲
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) |
给主人留下些什么吧!~~