aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChouser <chouser@n01se.net>2015-01-23 22:54:15 -0500
committerChouser <chouser@n01se.net>2015-01-30 12:54:42 -0500
commitf2f11f6279e1b242ba75136cd037fabdd176118a (patch)
tree6c00050c0fd66af90a8da76daa9df7dacb82d631
parentde04357cd5f2954e2d682abb97ca2b3b90ea75d1 (diff)
downloadmal-f2f11f6279e1b242ba75136cd037fabdd176118a.tar.gz
mal-f2f11f6279e1b242ba75136cd037fabdd176118a.zip
Ocaml: rename Types.MalList to Types.List
-rw-r--r--ocaml/core.ml8
-rw-r--r--ocaml/printer.ml2
-rw-r--r--ocaml/reader.ml4
-rw-r--r--ocaml/step2_eval.ml4
-rw-r--r--ocaml/step3_env.ml10
-rw-r--r--ocaml/step4_if_fn_do.ml20
-rw-r--r--ocaml/types.ml2
7 files changed, 25 insertions, 25 deletions
diff --git a/ocaml/core.ml b/ocaml/core.ml
index c11c9f9..db3424a 100644
--- a/ocaml/core.ml
+++ b/ocaml/core.ml
@@ -18,13 +18,13 @@ let init env = begin
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 xs -> Types.List xs));
Env.set env (Types.Symbol "list?")
- (Types.Fn (function [Types.MalList _] -> Types.Bool true | _ -> Types.Bool false));
+ (Types.Fn (function [Types.List _] -> Types.Bool true | _ -> Types.Bool false));
Env.set env (Types.Symbol "empty?")
- (Types.Fn (function [Types.MalList []] -> Types.Bool true | _ -> Types.Bool false));
+ (Types.Fn (function [Types.List []] -> 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));
+ (Types.Fn (function [Types.List 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));
diff --git a/ocaml/printer.ml b/ocaml/printer.ml
index fc9e47b..59c025d 100644
--- a/ocaml/printer.ml
+++ b/ocaml/printer.ml
@@ -13,6 +13,6 @@ let rec pr_str mal_obj print_readably =
if print_readably
then "\"" ^ (Str.global_replace (Str.regexp "\\([\"\\]\\)") "\\\\\\1" s) ^ "\""
else s
- | Types.MalList xs ->
+ | Types.List xs ->
"(" ^ (join " " (List.map (fun s -> pr_str s print_readably) xs)) ^ ")"
| Types.Fn f -> "#<fn>"
diff --git a/ocaml/reader.ml b/ocaml/reader.ml
index c32fa91..58e72fe 100644
--- a/ocaml/reader.ml
+++ b/ocaml/reader.ml
@@ -43,7 +43,7 @@ let rec read_list list_reader =
tokens = reader.tokens}
and read_quote sym tokens =
let reader = read_form tokens in
- {form = Types.MalList [ Types.Symbol sym; reader.form ];
+ {form = Types.List [ Types.Symbol sym; reader.form ];
tokens = reader.tokens}
and read_form all_tokens =
match all_tokens with
@@ -56,7 +56,7 @@ and read_form all_tokens =
| "~@" -> read_quote "splice-unquote" tokens
| "[" | "(" | "{" -> let list_reader =
read_list {list_form = []; tokens = tokens} in
- {form = Types.MalList list_reader.list_form;
+ {form = Types.List list_reader.list_form;
tokens = list_reader.tokens}
| _ -> {form = read_atom token; tokens = tokens}
diff --git a/ocaml/step2_eval.ml b/ocaml/step2_eval.ml
index af8667c..d5ec9a3 100644
--- a/ocaml/step2_eval.ml
+++ b/ocaml/step2_eval.ml
@@ -23,12 +23,12 @@ let rec eval_ast ast env =
| Types.Symbol s ->
(try Env.find s !env
with Not_found -> raise (Invalid_argument ("Symbol '" ^ s ^ "' not found")))
- | Types.MalList xs -> Types.MalList (List.map (fun x -> eval x env) xs)
+ | Types.List 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.MalList ((Types.Fn f) :: args) -> (f args)
+ | Types.List ((Types.Fn f) :: args) -> (f args)
| _ -> result
let read str = Reader.read_str str
diff --git a/ocaml/step3_env.ml b/ocaml/step3_env.ml
index d7939bf..3f64cae 100644
--- a/ocaml/step3_env.ml
+++ b/ocaml/step3_env.ml
@@ -15,14 +15,14 @@ end
let rec eval_ast ast env =
match ast with
| Types.Symbol s -> Env.get env ast
- | Types.MalList xs -> Types.MalList (List.map (fun x -> eval x env) xs)
+ | Types.List xs -> Types.List (List.map (fun x -> eval x env) xs)
| _ -> ast
and eval ast env =
match ast with
- | Types.MalList [(Types.Symbol "def!"); key; expr] ->
+ | Types.List [(Types.Symbol "def!"); key; expr] ->
let value = (eval expr env) in
Env.set env key value; value
- | Types.MalList [(Types.Symbol "let*"); (Types.MalList bindings); body] ->
+ | Types.List [(Types.Symbol "let*"); (Types.List bindings); body] ->
(let sub_env = Env.make (Some env) in
let rec bind_pairs = (function
| sym :: expr :: more ->
@@ -32,9 +32,9 @@ and eval ast env =
| [] -> ())
in bind_pairs bindings;
eval body sub_env)
- | Types.MalList _ ->
+ | Types.List _ ->
(match eval_ast ast env with
- | Types.MalList ((Types.Fn f) :: args) -> f args
+ | Types.List ((Types.Fn f) :: args) -> f args
| _ -> raise (Invalid_argument "Cannot invoke non-function"))
| _ -> eval_ast ast env
diff --git a/ocaml/step4_if_fn_do.ml b/ocaml/step4_if_fn_do.ml
index 6580dd6..bf8a5ab 100644
--- a/ocaml/step4_if_fn_do.ml
+++ b/ocaml/step4_if_fn_do.ml
@@ -3,14 +3,14 @@ let repl_env = Env.make (Some Core.ns)
let rec eval_ast ast env =
match ast with
| Types.Symbol s -> Env.get env ast
- | Types.MalList xs -> Types.MalList (List.map (fun x -> eval x env) xs)
+ | Types.List xs -> Types.List (List.map (fun x -> eval x env) xs)
| _ -> ast
and eval ast env =
match ast with
- | Types.MalList [(Types.Symbol "def!"); key; expr] ->
+ | Types.List [(Types.Symbol "def!"); key; expr] ->
let value = (eval expr env) in
Env.set env key value; value
- | Types.MalList [(Types.Symbol "let*"); (Types.MalList bindings); body] ->
+ | Types.List [(Types.Symbol "let*"); (Types.List bindings); body] ->
(let sub_env = Env.make (Some env) in
let rec bind_pairs = (function
| sym :: expr :: more ->
@@ -20,19 +20,19 @@ and eval ast env =
| [] -> ())
in bind_pairs bindings;
eval body sub_env)
- | Types.MalList ((Types.Symbol "do") :: body) ->
+ | Types.List ((Types.Symbol "do") :: body) ->
List.fold_left (fun x expr -> eval expr env) Types.Nil body
- | Types.MalList [Types.Symbol "if"; test; then_expr; else_expr] ->
+ | Types.List [Types.Symbol "if"; test; then_expr; else_expr] ->
if Types.to_bool (eval test env) then (eval then_expr env) else (eval else_expr env)
- | Types.MalList [Types.Symbol "if"; test; then_expr] ->
+ | Types.List [Types.Symbol "if"; test; then_expr] ->
if Types.to_bool (eval test env) then (eval then_expr env) else Types.Nil
- | Types.MalList [Types.Symbol "fn*"; Types.MalList arg_names; expr] ->
+ | Types.List [Types.Symbol "fn*"; Types.List arg_names; expr] ->
Types.Fn
(function args ->
let sub_env = Env.make (Some env) in
let rec bind_args a b =
(match a, b with
- | [Types.Symbol "&"; name], args -> Env.set sub_env name (Types.MalList args);
+ | [Types.Symbol "&"; name], args -> Env.set sub_env name (Types.List args);
| (name :: names), (arg :: args) ->
Env.set sub_env name arg;
bind_args names args;
@@ -40,9 +40,9 @@ and eval ast env =
| _ -> raise (Invalid_argument "Bad param count in fn call"))
in bind_args arg_names args;
eval expr sub_env)
- | Types.MalList _ ->
+ | Types.List _ ->
(match eval_ast ast env with
- | Types.MalList ((Types.Fn f) :: args) -> f args
+ | Types.List ((Types.Fn f) :: args) -> f args
| _ -> raise (Invalid_argument "Cannot invoke non-function"))
| _ -> eval_ast ast env
diff --git a/ocaml/types.ml b/ocaml/types.ml
index badfee3..34dba05 100644
--- a/ocaml/types.ml
+++ b/ocaml/types.ml
@@ -1,5 +1,5 @@
type mal_type =
- | MalList of mal_type list
+ | List of mal_type list
| Int of int
| Symbol of string
| Keyword of string