diff options
Diffstat (limited to 'ocaml/printer.ml')
| -rw-r--r-- | ocaml/printer.ml | 14 |
1 files changed, 13 insertions, 1 deletions
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 -> "#<fn>" |
