change env implementations to assoc list
[lambda.git] / code / untyped_evaluator_complete.ml
index ed34138..d9b158c 100644 (file)
@@ -56,16 +56,16 @@ and result = term
 
 (* This simplified code just provides a single implementation of environments;
    but the fuller code provides more. *)
-and env = identifier -> term option
+and env = (identifier * term) list
 
 (* Operations for environments *)
-let empty = fun _ -> None
-let shift (ident : identifier) binding env =
-  fun (sought_ident : identifier) ->
-    if ident = sought_ident
-    then Some binding
-    else env sought_ident
-let lookup sought_ident env = env sought_ident
+let empty = []
+let shift (ident : identifier) binding env = (ident,binding) :: env
+let rec lookup (sought_ident : ident) (env : env) : term option =
+  match env with
+  | [] -> None
+  | (ident, binding) :: _ when ident = sought_ident -> Some binding
+  | _ :: env' -> lookup sought_ident env'
 
   
 (*