2.12 Environment Control (Prolog flags)
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • Overview
        • Environment Control (Prolog flags)
          • current_prolog_flag/2
          • set_prolog_flag/2
          • create_prolog_flag/3
          • push_prolog_flag/2
          • pop_prolog_flag/1
    • Packages
Availability:built-in
push_prolog_flag(:Key, +Value)
Save the current thread-local value of Key and set it to Value. 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)).