anchor.diff:  %% get_vars(Env) -> Vars.
   %% clr_vars(Env) -> Env.
   %% set_vars(Vars, Env) -> Env.
  +%% fold_vars(Fun, Acc, Env) -> Acc.
   %% get_funs(Env) -> Funs.
   %% clr_funs(Env) -> Env.
   %% set_funs(Funs, Env) -> Env.
  +%% fold_funs(Fun, Acc, Env) -> Acc.
  +%% fold_macros(Fun, Acc, Env) -> Acc.
   %% add_vbinding(Name, Val, Env) -> Env.
   %% add_vbindings([{Name,Val}], Env) -> Env.
   %% is_vbound(Symb, Env) -> bool().
  
positive.code: -module(lfe_env).
  
  -export([new/0,add_env/2,
           get_vars/1,clr_vars/1,set_vars/2,get_funs/1,clr_funs/1,set_funs/2,
           add_vbinding/3,add_vbindings/2,is_vbound/2,get_vbinding/2,
           fetch_vbinding/2,del_vbinding/2,
           add_fbinding/4,add_fbindings/2,
  
negative.code: %%  is no longer a legal guard bif but must be explicitly called with
  %%  module erlang.
  
  new() -> #env{vars=?NEW(),funs=?NEW()}. 
  
  -ifdef(HAS_MAPS).
  add_env(#env{vars=Vs1,funs=Fs1}, #env{vars=Vs2,funs=Fs2}) ->
      #env{vars=maps:merge(Vs2, Vs1),             %Always take left env
           funs=maps:merge(Fs2, Fs1)}.
  -else.
  add_env(#env{vars=Vs1,funs=Fs1}, #env{vars=Vs2,funs=Fs2}) ->
      Merge = fun (_, V1, _) -> V1 end,           %Always take left env
      #env{vars=orddict:merge(Merge, Vs1, Vs2),
           funs=orddict:merge(Merge, Fs1, Fs2)}.
  -endif.
  
  get_vars(Env) -> Env#env.vars.
  clr_vars(Env) -> Env#env{vars=?NEW()}.
  set_vars(Vars, Env) -> Env#env{vars=Vars}.
  fold_vars(Fun, Acc, Env) ->
      ?FOLD(Fun, Acc, Env#env.vars).
  
  get_funs(Env) -> Env#env.funs.
  clr_funs(Env) -> Env#env{funs=?NEW()}.
  set_funs(Funs, Env) -> Env#env{funs=Funs}.
  
  fold_funs(Fun, Acc, Env) ->
      Ofun = fun (F, {function,Fs}, Ac) ->        %Function
                     Ffun = fun ({Ar,Def}, A) ->
                                    Fun(F, Ar, Def, A)
                            end,
                     lists:foldl(Ffun, Ac, Fs);
                 (_, _, A) -> A                   %Macro
             end,
      ?FOLD(Ofun, Acc, Env#env.funs).
  
  fold_macros(Fun, Acc, Env) ->
      Ofun = fun (F, {macro,Def}, A) ->           %Macro
                     Fun(F, Def, A);
                 (_, _, A) -> A                   %Function
             end,
      ?FOLD(Ofun, Acc, Env#env.funs).
  
  %% Variables.
  
  add_vbinding(N, V, #env{vars=Vs}=Env) ->
      Env#env{vars=?PUT(N, V, Vs)}.
  
  add_vbindings(Vbs, #env{vars=Vs0}=Env) ->
      Vs1 = foldl(fun ({N,V}, Vs) -> ?PUT(N, V, Vs) end, Vs0, Vbs),
      Env#env{vars=Vs1}.
  
  is_vbound(N, #env{vars=Vs}) ->
      ?IS_KEY(N, Vs).
  
  get_vbinding(N, #env{vars=Vs}) ->
      case ?FIND(N, Vs) of
          {ok,V} -> {yes,V};
          error -> no
      end.
  
  fetch_vbinding(N, #env{vars=Vs}) ->
      ?GET(N, Vs).
  
  del_vbinding(N, #env{vars=Vs}=Env) ->
      Env#env{vars=?ERASE(N, Vs)}.
  
  %% Functions.
  
  