From 59d10e1bd703f65e12fef85bceef4204f82685fb Mon Sep 17 00:00:00 2001 From: Chouser Date: Thu, 22 Jan 2015 02:59:48 -0500 Subject: Ocaml: Added step 1, missing some optional functionality --- ocaml/printer.ml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ocaml/printer.ml (limited to 'ocaml/printer.ml') diff --git a/ocaml/printer.ml b/ocaml/printer.ml new file mode 100644 index 0000000..30e4415 --- /dev/null +++ b/ocaml/printer.ml @@ -0,0 +1,15 @@ +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 = + match mal_obj with + | Types.Int i -> string_of_int i + | Types.Symbol s -> s + | Types.Keyword s -> ":" ^ s + | Types.Nil -> "nil" + | Types.Bool true -> "true" + | Types.Bool false -> "false" + | Types.String s -> "\"" + ^ (Str.global_replace (Str.regexp "\"") "\\\"" s) + ^ "\"" + | Types.MalList xs -> "(" ^ (join " " (List.map pr_str xs)) ^ ")" -- cgit v1.2.3