另一个规则作为序言中规则的参数

Another rule as argument to a rule in prolog

这是我的序言文件。

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

我想查询这样的东西daughter(X, mother(Y, john)). 可能吗?

我想找约翰妈妈的女儿。

我从 here 的 'Asking Questions with Structures'

得到了这个想法

尝试

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

查询 -> mothers_daughter(john, Y).

编辑: 女儿(X,母亲(Y,Z)):- 女性(X),母亲(Y,X)。

类似的东西?

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

这将匹配 Y 作为 john 的母亲,然后 X 作为 Y 的女儿。所以 X 将是 john 母亲的女儿。