9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-07 14:03:37 +01:00
qp2/ocaml/Qputils.ml

59 lines
1.3 KiB
OCaml
Raw Normal View History

2019-01-25 11:39:31 +01:00
open Sexplib
(*
let rec transpose = function
| [] -> []
| []::tail -> transpose tail
| (x::t1)::t2 ->
let new_head = (x::(List.map List.hd t2))
and new_tail = (transpose (t1 :: (List.map List.tl t2) ))
in
new_head @ new_tail
;;
*)
let input_to_sexp s =
let result =
String_ext.split ~on:'\n' s
|> List.filter (fun x-> (String_ext.strip x) <> "")
|> List.map (fun x-> "("^
(Str.global_replace (Str.regexp "=") " " x)
^")")
|> String.concat ""
in
print_endline ("("^result^")");
"("^result^")"
|> Sexp.of_string
let rmdir dirname =
let rec remove_one dir =
Sys.chdir dir;
Sys.readdir "."
|> Array.iter (fun x ->
match (Sys.is_directory x, Sys.file_exists x) with
| (true, _) -> remove_one x
| (_, true) -> Sys.remove x
| _ -> failwith ("Unable to remove file "^x^".")
);
Sys.chdir "..";
Unix.rmdir dir
in
remove_one dirname
2019-03-13 13:02:29 +01:00
let input_lines ic =
let n = in_channel_length ic in
let s = Bytes.create n in
really_input ic s 0 n;
close_in ic;
Bytes.to_string s
|> String_ext.split ~on:'\n'
2019-03-13 15:49:57 +01:00
let string_of_string s = s
2020-05-25 11:31:28 +02:00
let list_map f l =
List.rev_map f l
|> List.rev