Save the current thread-local value of Key and set it to
Value. Raises a permission error if Key is a
shared flag (see create_prolog_flag/3).
If Key does not exist, it is created (only in the calling
thread) and the pushed state records its absence. Nestable and paired
with pop_prolog_flag/1.
These predicates have been designed with two main use cases in mind.
First of all scoped compilation with different flags. For example, the
code below keeps the clause as written. Without locally modifying this
flag the 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)).