理解 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?
该谓词允许元编程,即推理 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.