diff options
| author | Chouser <chouser@n01se.net> | 2015-01-22 02:59:48 -0500 |
|---|---|---|
| committer | Chouser <chouser@n01se.net> | 2015-01-30 12:54:42 -0500 |
| commit | 59d10e1bd703f65e12fef85bceef4204f82685fb (patch) | |
| tree | d603eb4b18dca19d4351b40164765363f9866d3c /ocaml/printer.ml | |
| parent | ca51c4f77235d8f9b8606ebc8c255778c83c9050 (diff) | |
| download | mal-59d10e1bd703f65e12fef85bceef4204f82685fb.tar.gz mal-59d10e1bd703f65e12fef85bceef4204f82685fb.zip | |
Ocaml: Added step 1, missing some optional functionality
Diffstat (limited to 'ocaml/printer.ml')
| -rw-r--r-- | ocaml/printer.ml | 15 |
1 files changed, 15 insertions, 0 deletions
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)) ^ ")" |
