理解 Clause/2 谓词
我目前正在尝试学习一些 Prolog(使用 ECLiPSe)。我有时会遇到 Clause/2 谓词,但我无法理解它的用途。我读了一些参考文献(例如 这个),但我仍然不明白它在什么情况下有用。有人可以给我提供一个简单的例子或解释吗?
I'm currently trying to learn some Prolog (using ECLiPSe). From time to time I come across the clause/2 predicate, but I fail to understand what it is used for. I read some references (e.g. this one), but I still don't get in what case it could be useful. Can someone provide me with an easy example or explanation of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该谓词允许元编程,即推理 Prolog 程序。
SWI-Prolog 在 ao、
explain
谓词中使用clause/2
:以及在 约束处理规则。我怀疑它对于进行归纳逻辑编程和各种其他Prolog扩展也很有用。
有关 Prolog 中元编程的完整介绍,请参阅 Sterling 和 Shapiro 的《The Art of Prolog》。
This predicate allows metaprogramming, i.e. reasoning about your Prolog program.
SWI-Prolog uses
clause/2
in, a.o., theexplain
predicate:and in the implementation of Constraint Handling Rules. I suspect it's also useful for doing inductive logic programming and various other Prolog extensions.
For a thorough introduction to metaprogramming in Prolog, see The Art of Prolog by Sterling and Shapiro.
一种用途是非常优雅的 quine :b
在这里找到
了当然,正如拉斯曼斯所说,元编程的一个例子
one use is a really elegant quine :b
found here
which is of course a case of meta-programming as larsmans said