三个Prolog问题包括祖父母

问题描述 投票:0回答:1

这个程序将使用SWI Prolog进行测试。

Family.pl包含了家庭成员的事实,谁和谁结婚了,诸如此类的事情。

必须在底部添加规则,并提交修改后的文件。

  1. 编写一个 motherInLaw(X,Y) 谓词 XY的婆婆。

  2. 写一个 grandParent(X,Y) 谓词 XY的祖父母。

  3. 写一个 grandMother(X,Y) 谓词 XY的奶奶。

谢谢你们!

这是我自己的答案,请你们看一下,告诉我是否正确?谢谢你们

motherInLaw(X, Y) : mother(X, Z),couple(Z, Y)

grandParent(X, Y) : parent(X, Z),parent(Z, Y)

grandMother(Z, Y) : mother(X, Z),parent(Z, Y)
prolog swi-prolog
1个回答
3
投票

你需要写 :- 而不是 :. 句末

grandmother/2 谓语看起来很奇怪。其实我觉得分句的头应该是 grandMother(X,Y).

© www.soinside.com 2019 - 2024. All rights reserved.