How would one go about and bootstrap setarg_with_occurs_check/3
in
Prolog. It seems Prolog has two ways to create cyclic data structures.
Not only unification can do that, but also setarg/3:
/* SWI-Prolog 8.3.26 */
?- X = f(X).
X = f(X).
?- X = f(0), setarg(1,X,X).
X = f(X).
Lets say I want the analogue of unify_with_occurs_check/2
for
setarg/3
. How would one go about and implement the same?
(BTW In some Prolog systems setarg/3 sometimes goes by the
name change_arg/3, and some even don't have it at all)
I think you can use the ISO predicate
acyclic_term/1
. Thus, in SWI-Prolog, you can define:Examples: