我有一个像下面这样的家谱:
Dasarath - Kousalya
|
Raam - Sita
|
Lava, Kusa
我的事实是:
male("Dasarath").
male("Raam").
male("Lava").
male("Kusa").
female("Kousalya").
female("Sita").
child("Raam", "Dasarath").
child("Raam", "Kousalya").
child("Lava", "Raam").
child("Lava", "Sita").
child("Kusa", "Raam").
child("Kusa", "Sita").
我有一个定义父母的规则。
parent(ParentName, ChildName) :- child(ChildName, ParentName).
还有定义父亲和母亲的规则。
father(FatherName, ChildName) :- parent(FatherName, ChildName), male(FatherName).
mother(MotherName, ChildName) :- parent(MotherName, ChildName), female(MotherName).
现在问题来了,当我将兄弟的规则定义为
brother(BrotherName, PersonName) :- father(ParentName, BrotherName), father(ParentName, PersonName),
male(BrotherName), not BrotherName = PersonName.
我使用查询执行它
brother(BrotherName, PersonName)
结果为
brother(BrotherName, PersonName)
BROTHERNAME = "Lava".
PERSONNAME = "Kusa".
BROTHERNAME = "Kusa".
PERSONNAME = "Lava".
2 Solutions
我被要求只为这个查询带来一个结果。我无法搜索正确的问题。如果有解决方案,请提供一个或告诉我 Prolog 为何如此工作的原因。