From b7ffcab96166f15d6203551ffbc487da5076f92e Mon Sep 17 00:00:00 2001 From: Chouser Date: Sat, 24 Jan 2015 00:44:51 -0500 Subject: Ocaml: Add read, print for vector, map --- ocaml/printer.ml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'ocaml/printer.ml') diff --git a/ocaml/printer.ml b/ocaml/printer.ml index 59c025d..1257a69 100644 --- a/ocaml/printer.ml +++ b/ocaml/printer.ml @@ -1,7 +1,16 @@ let join sep xs = List.fold_left (fun a x -> if a = "" then x else a ^ sep ^ x) "" xs -let rec pr_str mal_obj print_readably = +let rec pr_pairs xs str print_readably = match xs with + | k :: v :: more -> pr_pairs more ((if str = "" then str else (str ^ ", ")) + ^ (pr_str k print_readably) + ^ " " + ^ (pr_str v print_readably)) + print_readably + | _ :: [] -> raise (Invalid_argument "Partition requires even number of items") + | [] -> str + +and pr_str mal_obj print_readably = match mal_obj with | Types.Int i -> string_of_int i | Types.Symbol s -> s @@ -15,4 +24,7 @@ let rec pr_str mal_obj print_readably = else s | Types.List xs -> "(" ^ (join " " (List.map (fun s -> pr_str s print_readably) xs)) ^ ")" + | Types.Vector xs -> + "[" ^ (join " " (List.map (fun s -> pr_str s print_readably) xs)) ^ "]" + | Types.Map xs -> "{" ^ pr_pairs xs "" print_readably ^ "}" | Types.Fn f -> "#" -- cgit v1.2.3