A global environment/context management system for Scryer Prolog providing key-value metadata storage one level of abstraction above the blackboard.
This library provides a clean interface for managing global state in Prolog programs using association trees (AVL trees) backed by the blackboard. It offers:
- Global persistent storage - Changes persist across backtracking
- Backtrackable local storage - Changes roll back on backtracking
- Type-safe reified predicates - Use if_/3 for conditional logic without cuts
- Once-only initialization - Prevent accidental double initialization
- Key existence checking - Efficiently check for key presence
Copy environment.pl to your project's library directory or ensure it's in your Scryer Prolog load path.
- library(reif) - Reified predicates for conditional logic
- library(assoc) - Association trees (AVL trees)
- library(iso_ext) - ISO extensions including blackboard predicates
Retrieve the current global environment as an association tree.
Replace the entire global environment (persistent).
Replace the entire global environment (backtrackable).
Set a key-value pair globally (persistent across backtracking).
Set a flag (key with value true) globally.
Set a key-value pair only if it doesn't exist. If it exists with a different value, throws an error.
Set a flag only once. Throws error if already set with different value.
Set a key-value pair locally (backtrackable).
Set a flag locally (backtrackable).
Retrieve value for a key. Throws key_error if key doesn't exist.
Retrieve value for a key, or unify with NotFound if key doesn't exist.
Check if a flag exists (deterministic success/failure).
Reified version: unifies Truth with true or false.
Check if key exists with specific value (deterministic).
Reified version of key-value check.
Alias for env_check_key_val_t/3.
Assert that a flag exists (throws error if missing).
Remove a key from the environment (persistent).
Remove a key from the environment (backtrackable).
The environment is initialized exactly once using term_expansion/2. The first time the module is loaded, it creates an empty association tree and stores it in the blackboard under global_context.
This library extensively uses reified predicates from library(reif) for conditional logic without cuts. This enables pure, declarative programming with backtracking-friendly conditionals.
- All operations are O(log n) due to the underlying AVL tree implementation
- Key lookups are efficient even with thousands of entries
- Reified key existence checking avoids expensive exception handling
BSD-2-Clause (compatible with Scryer Prolog standard libraries)
Jay
0.1.0
.png)

