如何在 SWI-Prolog 的所有统一中启用发生检查? [英] How to enable the occurs check in all unifications in SWI-Prolog?
问题描述
根据维基百科:
为所有统一提供声音统一的实现是 Qu-Prolog 和 Strawberry Prolog,以及(可选地,通过运行时标志):XSB、SWI-Prolog 和 Tau Prolog.
Implementations offering sound unification for all unifications are Qu-Prolog and Strawberry Prolog and (optionally, via a runtime flag): XSB, SWI-Prolog and Tau Prolog.
但是,当我执行 apropos(occur)
时,它只找到 unify_with_occurs_check/2
.man 页面没有提到发生"任何一个.如何在 SWI-Prolog 中为所有统一启用发生检查?
However, when I do apropos(occur)
it only finds unify_with_occurs_check/2
. The man page doesn't mention "occur" either. How can the occurs check be enabled for all unifications in SWI-Prolog?
推荐答案
在 Environment Control,它列出了系统的标志.occurs_check
标志是控制发生统一检查的标志.
In the section on Environment Control, it lists the flags of the system. The occurs_check
flag is the one that controls occurs checks for unification.
您可以通过以下方式设置标志:
You can set the flag with:
:- set_prolog_flag(occurs_check, true).
例如:
?- X = f(X).
X = f(X).
?- set_prolog_flag(occurs_check, true).
true.
?- X = f(X).
false.
所以首先它统一了 X
和 f(X)
.如果我们稍后将 occurs_check
设置为 true
,那么如果我们再次尝试将 X
与 f(X)
统一,它失败了.
So first it unifies X
with f(X)
. If we later set the occurs_check
to true
, then if we try to unify X
again with f(X)
, it fails.
这篇关于如何在 SWI-Prolog 的所有统一中启用发生检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!