X = 42 is normally moved into the head.
:- push_prolog_flag(optimise_unify, false).
p(X) :-
X = 42,
format('The answer to the ultimate question~n').
:- pop_prolog_flag(optimise_unify).
Second, runtime scoping. For example, execute a goal with occurs checking:27Be aware that the “pop” happens when Goal has completed. Notably it is not immediately executed if Goal succeeds with a choice point.
call_with_occurs_check(Goal) :-
setup_call_cleanup(
push_prolog_flag(occurs_check, true),
Goal,
pop_prolog_flag(occurs_check)).