diff options
| author | Chouser <chouser@n01se.net> | 2015-01-25 23:30:37 -0500 |
|---|---|---|
| committer | Chouser <chouser@n01se.net> | 2015-01-30 12:54:42 -0500 |
| commit | a878f3bb778513c0cc8bbeb1a8ff61664e43de29 (patch) | |
| tree | 9024de3b223d78abef619c4ee36316c24f4bee19 /ocaml/step2_eval.ml | |
| parent | b7ffcab96166f15d6203551ffbc487da5076f92e (diff) | |
| download | mal-a878f3bb778513c0cc8bbeb1a8ff61664e43de29.tar.gz mal-a878f3bb778513c0cc8bbeb1a8ff61664e43de29.zip | |
Ocaml: Use a real map type
T.Map is now a real OCaml binary-tree map, and supports arbitrary mal value
types for both keys and values. Metadata support is provided in the data
objects, but not yet in the printer, reader, or core library.
Diffstat (limited to 'ocaml/step2_eval.ml')
| -rw-r--r-- | ocaml/step2_eval.ml | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ocaml/step2_eval.ml b/ocaml/step2_eval.ml index d5ec9a3..7be4a3e 100644 --- a/ocaml/step2_eval.ml +++ b/ocaml/step2_eval.ml @@ -1,3 +1,5 @@ +module T = Types.Types + module Env = Map.Make ( String @@ -7,9 +9,9 @@ module Env = end)*) ) -let num_fun f = Types.Fn +let num_fun f = T.Fn (function - | [(Types.Int a); (Types.Int b)] -> Types.Int (f a b) + | [(T.Int a); (T.Int b)] -> T.Int (f a b) | _ -> raise (Invalid_argument "Numeric args required for this Mal builtin")) let repl_env = ref (List.fold_left (fun a b -> b a) Env.empty @@ -20,15 +22,15 @@ let repl_env = ref (List.fold_left (fun a b -> b a) Env.empty let rec eval_ast ast env = match ast with - | Types.Symbol s -> + | T.Symbol { T.value = s } -> (try Env.find s !env with Not_found -> raise (Invalid_argument ("Symbol '" ^ s ^ "' not found"))) - | Types.List xs -> Types.List (List.map (fun x -> eval x env) xs) + | T.List { T.value = xs } -> Types.list (List.map (fun x -> eval x env) xs) | _ -> ast and eval ast env = let result = eval_ast ast env in match result with - | Types.List ((Types.Fn f) :: args) -> (f args) + | T.List { T.value = ((T.Fn f) :: args) } -> (f args) | _ -> result let read str = Reader.read_str str |
