【发布时间】:2017-07-26 13:46:51
【问题描述】:
当我试图查看谁是谁的兄弟和姐妹时,它给了我儿子和女儿,我找不到错误......
father(pedro-i,fernando-i).
father(pedro-i,beatriz(1347)).
father(pedro-i,joão(1349)).
father(pedro-i,dinis(1354)).
father(pedro-i,joão_grão_mestre_da_ordem_de_avis).
mother(constança(1320),luis).
mother(constança(1320),maria(1342)).
mother(constança(1320),fernando-i).
mother(inês_de_castro,beatriz(1347)).
任何其他我欣赏的意见
ancestor(X,Y) :- mother(X,Y).
ancestor(X,Y) :- father(X,Y).
if_then_else(X,Y,male) :- father(X,Y).
if_then_else(X,Y,female) :- mother(X,Y).
son(X,Y) :- father(X,Y).
sister(X,Y) :- ancestor(Z,Y),X\==Y,if_then_else(X,Y,female).
brother(X,Y) :- ancestor(Z,Y),X\==Y,if_then_else(X,Y,male).
descendent (X,Y) :- filho(X,Y).
descendent (X,Y) :- filho(X,Z),descendent (Z,Y).
grandfather(X,Y) :- ancestor(X,Z),ancestor(Z,Y).
grandmother(X,Y) :- ancestor(X,Z),ancestor(Z,Y).
grandchildren(X,Y) :- ancestor(Z,X),ancestor(Y,Z).
uncle(X,Y) :- brother(X,Z),ancestor(Z,Y).
【问题讨论】:
-
您输入什么查询?你得到什么结果?你期待什么结果?
-
例如,如果我输入以下查询:'brother(X,fernando-i)。'我得到:'X=pedro-i',我想得到:'X=joão(1349)。 X=迪尼斯(1354)。 X=joão_grão_mestre_da_ordem_de_avis) ' 只有男性,如果我问姐姐只有女性@lurker
-
s/pedro-i/pedro_i/g -
@false 不明白你想说什么。
-
不要像
pedro-i那样在名称中直接使用-,而是使用_。如果您真的坚持,请将整个名称放在引号中,例如'pedro-i'
标签: prolog family-tree