Backtrackable global variables

Author(s): Jose F. Morales, Rémy Haemmerlé.

This module provides a simple way to assign and read fully backtrackable global variables.

Global variables differ from storing information using dynamic predicates:

  • Global variables are semantically equivalent to a dictionary passed around as an implicit pair of variables:
    • only one value is associated to a variable at a time
    • the value associated to a variable can be replaced
    • any assignment is undone on backtracking
    • access cost is proportional to a unification
    • variable sharing is preserved during assignment
  • Keys of global variables are local to each module.
  • Contrary to dynamic predicates, there is no copy of terms. This is particularly interesting for large terms.

The implementation is based on a globally reachable structure in the heap, where each entry is allocated dynamically for each key.

Note that the current implementation has some limitations (see bug entries in this module).

Usage and interface

Documentation on exports



Associate the term Value with the atom Name. If Name does not refer to an existing global variable, an unbounded global variable Value is created and unified to Value. On backtracking the assignment is reversed. If Name is not a atom the predicate silently fails.



    Unifies Value with the current value of the global variable refered to by the atom Name. If Name does not refer to an exisiting global variable, a free unbound variable is created and unified with Value. If Name is not an atom the predicate silently fails.



      Enumerate all defined variables with their value. The order of enumeration is undefined.

        Documentation on imports

        This module has the following direct dependencies: