理解子句/ 2谓词

时间:2011-05-10 17:22:24

标签: prolog clause

我目前正在尝试学习一些Prolog(使用ECLiPSe)。我偶尔会遇到第2条谓词,但我不明白它的用途。我读了一些参考文献(例如this one),但我仍然不知道它可能有用。有人可以给我一个简单的例子或解释吗?

2 个答案:

答案 0 :(得分:3)

这个谓词允许元编程,即推理你的Prolog程序。

SWI-Prolog使用clause/2 in a.o.,explain谓词:

?- explain(member).
"member" is an atom
        Referenced from 12-th clause of pce_meta:pce_to_pl_type/3
lists:member/2 is a predicate defined in
        c:/program files/swi-prolog/library/lists.pl:81
        Referenced from 1-th clause of prolog_dialect:source_exports/2
        Referenced from 1-th clause of pce_config:term_description/2
        Referenced from 1-th clause of pce_config:config_attribute/2
        Referenced from 1-th clause of pce_config:load_config_key/2
        Referenced from 1-th clause of pce_config:term_description/3
        Referenced from 1-th clause of pce_config:current_config_path/1
        Referenced from 4-th clause of persistent_frame:has_specifier/1
true.

并在Constraint Handling Rules的实施中。我怀疑它对于inductive logic programming和其他各种Prolog扩展也很有用。

有关Prolog中元编程的全面介绍,请参阅Sterling和Shapiro的 Prolog的艺术

答案 1 :(得分:1)

一个用途是非常优雅的quine:b

quine :-
    clause(quine, A),
    portray_clause((quine:-A)).

找到here

当然是larsmans所说的元编程案例