diff options
| author | Chouser <chouser@n01se.net> | 2015-01-23 18:11:45 -0500 |
|---|---|---|
| committer | Chouser <chouser@n01se.net> | 2015-01-30 12:54:42 -0500 |
| commit | 9115534dc73fe18a12b3b2ecf436051b76bdd8a4 (patch) | |
| tree | 05ecbb01a3517e550cd25016481cc9c262ed6e3b /ocaml/core.ml | |
| parent | 79ba3d608878cf99d4a61960ae0a29e2e4a96745 (diff) | |
| download | mal-9115534dc73fe18a12b3b2ecf436051b76bdd8a4.tar.gz mal-9115534dc73fe18a12b3b2ecf436051b76bdd8a4.zip | |
Ocaml: Add step 4, but not str fns or optionals.
Diffstat (limited to 'ocaml/core.ml')
| -rw-r--r-- | ocaml/core.ml | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/ocaml/core.ml b/ocaml/core.ml new file mode 100644 index 0000000..4cec7f1 --- /dev/null +++ b/ocaml/core.ml @@ -0,0 +1,32 @@ +let ns = Env.make None + +let num_fun t f = Types.Fn + (function + | [(Types.Int a); (Types.Int b)] -> t (f a b) + | _ -> raise (Invalid_argument "Numeric args required for this Mal builtin")) + +let mk_int x = Types.Int x +let mk_bool x = Types.Bool x + +let init env = begin + Env.set env (Types.Symbol "+") (num_fun mk_int ( + )); + Env.set env (Types.Symbol "-") (num_fun mk_int ( - )); + Env.set env (Types.Symbol "*") (num_fun mk_int ( * )); + Env.set env (Types.Symbol "/") (num_fun mk_int ( / )); + Env.set env (Types.Symbol "<") (num_fun mk_bool ( < )); + Env.set env (Types.Symbol "<=") (num_fun mk_bool ( <= )); + Env.set env (Types.Symbol ">") (num_fun mk_bool ( > )); + Env.set env (Types.Symbol ">=") (num_fun mk_bool ( >= )); + + Env.set env (Types.Symbol "list") (Types.Fn (function xs -> Types.MalList xs)); + Env.set env (Types.Symbol "list?") + (Types.Fn (function [Types.MalList _] -> Types.Bool true | _ -> Types.Bool false)); + Env.set env (Types.Symbol "empty?") + (Types.Fn (function [Types.MalList []] -> Types.Bool true | _ -> Types.Bool false)); + Env.set env (Types.Symbol "count") + (Types.Fn (function [Types.MalList xs] -> Types.Int (List.length xs) | _ -> Types.Int 0)); + Env.set env (Types.Symbol "=") + (Types.Fn (function [a; b] -> Types.Bool (a = b) | _ -> Types.Bool false)); + +end + |
