1:- module(ccenv, [ run_env/1, env_new/2, env_get/2, env_set/2, env_app/2, env_upd/3 ]).

Delimited context providing environment with mutable name-value map */

    4:- use_module(library(data/env), [init_env//0, get_key//2, set_key//2, upd_key//3]).    5:- use_module(library(ccstate), [run_state/4, app/2]).    6
    7:- meta_predicate run_env(0), env_app(+,2).
 run_env(+P:pred) is det
Run P inside a run_state/4 with the prompt set to env, providing an environment containing mutable key-value mappings.
   12run_env(Goal) :-
   13   init_env(_,S),
   14   run_state(env, Goal, S, _).
   15
   16env_new(R,X) :- app(env, ins_key(R,X)).
   17env_get(R,X) :- app(env, get_key(R,X)).
   18env_set(R,X) :- app(env, set_key(R,X)).
   19env_app(R,P) :- app(env, upd_key(R,X,Y)), call(P,X,Y).
   20env_upd(R,X,Y) :- app(env, upd_key(R,X,Y))