]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - math/util.ml
MediaWiki 1.17.4
[autoinstallsdev/mediawiki.git] / math / util.ml
1 (* vim: set sw=8 ts=8 et: *)
2
3 (* TODO document *)
4 let mapjoin f l = (List.fold_left (fun a b -> a ^ (f b)) "" l)
5
6 (* TODO document *)
7 let mapjoine e f = function
8     [] -> ""
9   | h::t -> (List.fold_left (fun a b -> a ^ e ^ (f b)) (f h) t)
10
11 (* Exception used by open_out_unless_exists below *)
12 exception FileAlreadyExists
13
14 (* Wrapper which raise an exception when output path already exist *)
15 let open_out_unless_exists path =
16     if Sys.file_exists path
17     then raise FileAlreadyExists
18     else open_out path
19
20 (* *)
21 let run_in_other_directory tmppath cmd =
22     let prevdir = Sys.getcwd () in(
23         Sys.chdir tmppath;
24         let retval = Sys.command cmd in
25             (Sys.chdir prevdir; retval)
26     )