Another rule as argument to a rule in prolog

≯℡__Kan透↙ 提交于 2019-12-24 11:35:39

问题


This is my prolog file.

male(bob).
male(john).

female(betty).
female(dana).

father(bob, john).
father(bob, dana).
mother(betty, john).
mother(betty, dana).

daughter(X, Y) :- female(X), mother(Y, X).

I want to query something like this daughter(X, mother(Y, john)). Is it possible?

I'm trying to get daughter of john's mother.

I got this idea from here under 'Asking Questions with Structures'


回答1:


Something like that ?

daughter(X, Y), mother(Y, john).

This will match Y as the mother of john and then X as the daughter of Y. So X will be the daughter of john mother.




回答2:


try

mothers_daughter(X, Y) :- mother(Z,X), daughter(Y,Z).

query -> mothers_daughter(john, Y).

EDIT: daughter(X, mother(Y, Z)):- female(X),mother(Y, X).



来源:https://stackoverflow.com/questions/32764537/another-rule-as-argument-to-a-rule-in-prolog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!