I wonder whether some Prolog system ever considered
extending the scope of the occurs check flag. Currently
there are two ways to create cycles:
?- X = f(X). X = f(X). ?- X = f(0), setarg(1,X,X). X = f(X).
The occurs check only bars creation of cycles from unification.
But cycles from setarg/3 are still allowed:
?- set_prolog_flag(occurs_check, true). true. ?- X = f(X). false. ?- X = f(0), setarg(1,X,X). X = f(X).
A setarg/3 check would be more difficult, since we cannot
check whether a variable occurs in a term. We would need
to see whether we reach the to be modified compound.
Is there such a check already available? It would possibly make
use of same_term/2, which is stronger than (==)/2?