【问题标题】:Three Prolog questions include grandparent三个 Prolog 问题包括祖父母
【发布时间】:2020-05-02 02:40:45
【问题描述】:

该程序将使用 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)

【问题讨论】:

  • 如果你能发布整个Family.pl源就太好了。

标签: prolog


【解决方案1】:

你需要在每个子句的末尾写:-而不是:.

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

【讨论】:

  • @IsabelleNewbie 抱歉,我不是母语人士,确实我很困惑
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-09
  • 2012-04-26
  • 1970-01-01
  • 2021-01-11
相关资源
最近更新 更多