Another rule as argument to a rule in prolog

2019-08-10 07:58发布

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'

标签: prolog
2条回答
贪生不怕死
2楼-- · 2019-08-10 08:22

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.

查看更多
迷人小祖宗
3楼-- · 2019-08-10 08:25

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).

查看更多
登录 后发表回答