How to enable the occurs check in all unifications in SWI-Prolog?

只愿长相守 提交于 2021-02-09 04:14:37

问题


According to Wikipedia:

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.

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?


回答1:


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).

For example:

?- X = f(X).
X = f(X).

?- set_prolog_flag(occurs_check, true).
true.

?- X = f(X).
false.

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.



来源:https://stackoverflow.com/questions/64838646/how-to-enable-the-occurs-check-in-all-unifications-in-swi-prolog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!