Ocaml: Use builtin String.concat instead of own join fun
authorChouser <chouser@n01se.net>
Wed, 28 Jan 2015 13:24:52 +0000 (08:24 -0500)
committerChouser <chouser@n01se.net>
Fri, 30 Jan 2015 17:54:43 +0000 (12:54 -0500)
ocaml/core.ml
ocaml/printer.ml

index 5cf06ba..f901228 100644 (file)
@@ -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")
index d63e5f0..8e71376 100644 (file)
@@ -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 "")