Seems to work
[rops.git] / environment.ml
blob620905ba64bd2f0735d4377a5f5bf72907ba23c3
1 open Types;;
2 module Environment = struct
3 (**********************************************************************
4 ENVIRONMENT
5 **********************************************************************)
6 let push_env_frame env formals actuals =
8 let h = Hashtbl.create (List.length formals) in
9 List.iter
10 (function (name, obj) -> Hashtbl.add h name obj )
11 (List.combine formals actuals);
12 h::env
15 let find_frame env k =
16 try
17 List.find (fun x -> Hashtbl.mem x k) env
18 with
19 Not_found -> raise (Scheme_eval_error ("undefined: "^k));;
21 let lookup env k =
22 try
23 Hashtbl.find (find_frame env k) k
24 with
25 Not_found -> raise (Scheme_eval_error ("undefined: "^k));;
27 let update env k v =
28 try
29 Hashtbl.replace (find_frame env k) k v
30 with
31 Not_found -> raise (Scheme_eval_error ("undefined: "^k));;
33 let current_env_frame = function
34 (e::rest) -> e
35 | [] -> assert false
38 let initial_env = [Hashtbl.create 1]
40 end