问题描述
Hilog 术语(即具有作为函子任意术语的化合物)是否仍被视为 XSB Prolog(或任何其他 Prolog)中的强大功能?目前是否有许多 XSB 项目使用此功能?例如,他们中的哪一个?
Are Hilog terms (i.e. compounds having as functors arbitrary terms) still regarded as a powerful feature in XSB Prolog (or any other Prolog) ?Are there many XSB projects currently using this feature ? which of them for example ?
我问是因为据我所知,使用 ISO 内置调用/N 同样可以进行高阶编程.
I ask since as far as I understand higher order programming is equally possible using the ISO built-in call/N.
具体来说,我想了解 XSB 是否仅仅出于历史原因使用 Hilog 术语,或者 Hilog 术语与当前的 ISO 标准相比是否具有相当大的优势.
Specifically, I would like to understand if XSB is using Hilog terms just for historical reasons or if Hilog terms have considerable advantages in comparison to the current ISO standard.
推荐答案
在 XSB 中,Hilog 术语与 XSB 独有的模块系统密切相关.XSB 有一个基于函子的模块系统.也就是说,在同一范围内,length(X)
可能属于一个模块,而 length(L, N)
可能属于另一个模块.因此,call(length(L), N)
可能引用一个模块,而 call(length(L, N))
可能引用另一个模块:
Within XSB, Hilog terms are very strongly connected to the module system which is unique to XSB. XSB has a functor based module system. That is, within the same scope length(X)
might belong to one module, whereas length(L, N)
might belong to another. As a consequence, call(length(L), N)
might refer to one module and call(length(L, N))
to another:
[Patch date: 2013/02/20 06:17:59]
| ?- use_module(basics,length/2).
yes
| ?- length(Xs,2).
Xs = [_h201,_h203]
yes
| ?- call(length(Xs),2).
Xs = [_h217,_h219]
yes
| ?- use_module(inex,length/1).
yes
| ?- length(Xs,2).
Xs = [_h201,_h203]
yes
| ?- call(length(Xs),2).
++Error[XSB/Runtime/P]: [Existence (No module inex exists)] in arg 1 of predicate load
| ?- call(call(length,Xs),2).
Xs = [_h228,_h230];
在这种情况下,call/N
和 Hilog 术语之间可能存在差异.然而,到目前为止,我还没有找到.
It might be that in such a context there are differences between call/N
and Hilog terms. I have, however, so far not found one.
历史上,Hilog 术语是在 1987-1989 年引入的.在那个时候,call/N
已经作为内置函数存在于 NU 中,并且作为 library(call)
存在于 Quintus Prolog 中,带有 只是粗略的文档.1984 年由 Richard O'Keefe 提出.另一方面,call/N
对于 Hilog 的作者来说显然是未知的,正如 Weidong Chen、Michael Kifer、David Scott Warren 的第 1101 页所举例说明的:HiLog:一阶高阶逻辑编程结构的语义.国家知识产权局1989. 1090-1114.麻省理工学院出版社.
Historically, Hilog terms have been introduced 1987-1989. At that point in time, call/N
already existed as built-ins in NU and as library(call)
in Quintus Prolog with only cursory documentation. It has been proposed 1984 by Richard O'Keefe. On the other hand, call/N
was clearly unknown to the authors of Hilog, as is exemplified on p.1101 of Weidong Chen, Michael Kifer, David Scott Warren: HiLog: A First-OrderSemantics for Higher-Order Logic Programming Constructs. NACLP1989. 1090-1114. MIT-Press.
... 泛型传递闭包也可以在 Prolog 中定义:
closure(R, X, Y) :- C =.. [R, X, Y], call(C).
closure(R, X, Y) :- C =.. [R, X, Z], call(C), closure(R, Z, Y).
然而,这与 HiLog(参见第 2.1 节)相比显然不够优雅,因为这既涉及从列表中构造一个术语,又涉及使用调用"将该术语反映到原子公式中.这个例子的重点是 Prolog 中高阶结构缺乏理论基础导致语法晦涩,这部分解释了为什么 Prolog 程序涉及这种结构是出了名的难以理解.
However, this is obviously inelegant compared to HiLog (see Section 2.1), since this involves both constructing a term out of a list and reflecting this term into an atomic formula using "call". The point of this example is that the lack of theoretical foundations for higher-order constructs in Prolog resulted in an obscure syntax, which partially explains why Prolog programs involving such constructs are notoriously hard to understand.
现在,这可以通过 call/N
来完成:
Now, this can be done with call/N
like so:
closure(R, X, Y) :- call(R, X, Y).
closure(R, X, Y) :- call(R, X, Z), closure(R, Z, Y).
这比 (=..)/2
版本更通用,因为 R
不再局限于作为一个原子.顺便说一句,我宁愿写:
Which is even more general than the (=..)/2
-version because R
is no longer restricted to being an atom. As an aside, I'd rather prefer to write:
closure(R_2, X0,X) :- call(R_2, X0,X1), closure0(R_2, X1,X).
closure0(_R_2, X,X).
closure0(R_2, X0,X) :- call(R_2, X0,X1), closure0(R_2, X1,X).
这篇关于HiLog 术语在现代 Prolog 中仍然有用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!