1 (* ========================================================================== *)
2 (* FLYSPECK - BOOK FORMALIZATION *)
4 (* HOL LIGHT pervasives *)
5 (* Author: Thomas C. Hales *)
7 (* ========================================================================== *)
10 (* This file contains Ocaml library functions *)
13 module Flyspeck_lib = struct
17 eval_command comes from
19 http://solaria.dimino.org/cgi-bin/darcsweb.cgi?r=peps;a=headblob;f=/src/core/peps_top.ml
22 If the expression is syntactically correct
23 and the evaluation raises an exception, then the return value is true.
27 let eval_command ?(silent=false) command =
28 let buffer = Buffer.create 512 in
29 let pp = Format.formatter_of_buffer buffer in
30 Format.pp_set_margin pp max_int;
33 Toploop.execute_phrase (not silent) pp
34 (!Toploop.parse_toplevel_phrase (Lexing.from_string (command ^ ";;")))
36 (true, Buffer.contents buffer)
38 let save = !Toploop.parse_use_file in
39 Toploop.parse_use_file := (fun _ -> raise exn);
40 Pervasives.ignore (Toploop.use_silently pp "/dev/null");
41 Toploop.parse_use_file := save;
42 (false, Buffer.contents buffer);;
44 (* eval_command ~silent:false "g `x=y`";; *)
47 (* process_to_string in strictbuild.hl *)
49 let svn_version() = "svn("^
50 (process_to_string ("svnversion -n " ^ flyspeck_dir))^
52 (process_to_string("svnversion -n " ^ hollight_dir))^
57 let unsplit d f = function
58 | (x::xs) -> List.fold_left (fun s t -> s^d^(f t)) (f x) xs
61 let join_comma = unsplit "," (fun x-> x);;
63 let join_lines = unsplit "\n" (fun x-> x);;
65 let join_space = unsplit " " (fun x-> x);;
67 let rec nub = function (* from lpproc.ml *)
69 | x::xs -> x::filter ((<>) x) (nub xs);;
75 let output_filestring tmpfile a =
76 let outs = open_out tmpfile in
77 let _ = try (Printf.fprintf outs "%s" a)
78 with _ as t -> (close_out outs; raise t) in
81 (* from glpk_link.ml *)
83 let load_and_close_channel do_close ic =
86 lf ic (Pervasives.input_line ic::a)
87 with End_of_file -> a in
89 if do_close then Pervasives.close_in ic else ();
92 let load_and_close_channel_true ic =
95 lf ic (Pervasives.input_line ic::a)
96 with End_of_file -> a | _ as t -> (Pervasives.close_in ic; raise t) in
98 let _ = Pervasives.close_in ic in
101 let load_file filename =
102 let ic = Pervasives.open_in filename in load_and_close_channel_true ic;;
107 let print_string_as_text = report;;
111 let com = "command -v " ^ s in
112 not(process_to_string com = "");;
117 let dest_decimal x = match strip_comb x with
119 div_num (dest_numeral a) (dest_numeral b)
120 | _ -> failwith ("dest_decimal: '" ^ string_of_term x ^ "'") ;;
122 let string_of_num' x = string_of_float (float_of_num x);;