diff options
| author | Chouser <chouser@n01se.net> | 2015-01-28 08:24:52 -0500 |
|---|---|---|
| committer | Chouser <chouser@n01se.net> | 2015-01-30 12:54:43 -0500 |
| commit | cc916d9d819d17cc47d34321440bf5a2683eac2e (patch) | |
| tree | ef8be520ffe3422d736487a69be3c56566ce487d | |
| parent | 44d4e31fc8387a52918992ed40bd4b20d7646f39 (diff) | |
| download | mal-cc916d9d819d17cc47d34321440bf5a2683eac2e.tar.gz mal-cc916d9d819d17cc47d34321440bf5a2683eac2e.zip | |
Ocaml: Use builtin String.concat instead of own join fun
| -rw-r--r-- | ocaml/core.ml | 8 | ||||
| -rw-r--r-- | ocaml/printer.ml | 7 |
2 files changed, 6 insertions, 9 deletions
diff --git a/ocaml/core.ml b/ocaml/core.ml index 5cf06ba..f901228 100644 --- a/ocaml/core.ml +++ b/ocaml/core.ml @@ -35,17 +35,17 @@ let init env = begin Env.set env (Types.symbol "pr-str") (T.Fn (function xs -> - T.String (Printer.join " " (List.map (fun s -> Printer.pr_str s true) xs)))); + T.String (String.concat " " (List.map (fun s -> Printer.pr_str s true) xs)))); Env.set env (Types.symbol "str") (T.Fn (function xs -> - T.String (Printer.join "" (List.map (fun s -> Printer.pr_str s false) xs)))); + T.String (String.concat "" (List.map (fun s -> Printer.pr_str s false) xs)))); Env.set env (Types.symbol "prn") (T.Fn (function xs -> - print_endline (Printer.join " " (List.map (fun s -> Printer.pr_str s true) xs)); + print_endline (String.concat " " (List.map (fun s -> Printer.pr_str s true) xs)); T.Nil)); Env.set env (Types.symbol "println") (T.Fn (function xs -> - print_endline (Printer.join " " (List.map (fun s -> Printer.pr_str s false) xs)); + print_endline (String.concat " " (List.map (fun s -> Printer.pr_str s false) xs)); T.Nil)); Env.set env (Types.symbol "compare") diff --git a/ocaml/printer.ml b/ocaml/printer.ml index d63e5f0..8e71376 100644 --- a/ocaml/printer.ml +++ b/ocaml/printer.ml @@ -1,8 +1,5 @@ module T = Types.Types -let join sep xs = - List.fold_left (fun a x -> if a = "" then x else a ^ sep ^ x) "" xs - let meta obj = match obj with | T.List { T.meta = meta } -> meta @@ -25,9 +22,9 @@ let rec pr_str mal_obj print_readably = then "\"" ^ (Str.global_replace (Str.regexp "\\([\"\\]\\)") "\\\\\\1" s) ^ "\"" else s | T.List { T.value = xs } -> - "(" ^ (join " " (List.map (fun s -> pr_str s r) xs)) ^ ")" + "(" ^ (String.concat " " (List.map (fun s -> pr_str s r) xs)) ^ ")" | T.Vector { T.value = xs } -> - "[" ^ (join " " (List.map (fun s -> pr_str s r) xs)) ^ "]" + "[" ^ (String.concat " " (List.map (fun s -> pr_str s r) xs)) ^ "]" | T.Map { T.value = xs } -> (Types.MalMap.fold (fun k v s -> s ^ (if s = "" then "{" else ", ") ^ (pr_str k r) ^ " " ^ (pr_str v r)) xs "") |
