prolog如何使用循环/递归连接数据

时间:2011-11-28 02:36:28

标签: loops recursion prolog

我收到了来自

的数据
father(adam, matt).
father(matt,frank).
father(frank,jim).

grandfather:-father(X,A),father(A,Y).

我如何实际使用递归搜索祖父或祖父?基本上是指使用循环的X到Y.

编辑:和所有可能的匹配,因为有更多的父亲和儿子的

谢谢!

1 个答案:

答案 0 :(得分:2)

exact function you need几乎是'prolog recursion'的第一个Google结果:

作为参考,您可以使用右侧规则的左侧,并获得递归。