为什么列举一些关系会打印出“假”。最后,而其他人没有?

时间:2019-05-24 19:29:47

标签: prolog prolog-toplevel

考虑以下示例简单的Prolog程序:

child(johnny, eve, john).
child(stan, eve, john).
child(barbs, ann, peter).
child(john, liz, james).

father(Child, Father) :- child(Child, _, Father).
mother(Child, Mother) :- child(Child, Mother, _).
parent(Child, Parent) :- father(Child, Parent).
parent(Child, Parent) :- mother(Child, Parent).
grandma(Child, Grandma) :- parent(Child, Parent), mother(Parent, Grandma).
grandpa(Child, Grandpa) :- parent(Child, Parent), father(Parent, Grandpa).

我注意到了一件令人惊讶的事情。列举其中一些关系(grandmagrandpa),最终会打印出false

?- grandma(Child, Grandma).
Child = johnny,
Grandma = liz ;
Child = stan,
Grandma = liz ;
false.

?-

枚举其他人不会:

?- mother(Child, Mother).
Child = johnny,
Mother = eve ;
Child = stan,
Mother = eve ;
Child = barbs,
Mother = ann ;
Child = john,
Mother = liz.

?- 

为什么会发生这种情况以及它取决于什么?

0 个答案:

没有答案