15604
|
1 |
(* Title: HOL/Tools/res_lib.ML
|
|
2 |
Author: Jia Meng, Cambridge University Computer Laboratory
|
|
3 |
ID: $Id$
|
|
4 |
Copyright 2004 University of Cambridge
|
15347
|
5 |
|
15604
|
6 |
Some auxiliary functions frequently used by files in this directory.
|
15347
|
7 |
*)
|
|
8 |
|
|
9 |
signature RES_LIB =
|
|
10 |
sig
|
|
11 |
|
15604
|
12 |
val flat_noDup : ''a list list -> ''a list
|
|
13 |
val list2str_sep : string -> string list -> string
|
|
14 |
val list_to_string : string list -> string
|
|
15 |
val list_to_string' : string list -> string
|
|
16 |
val no_BDD : string -> string
|
|
17 |
val no_blanks : string -> string
|
|
18 |
val no_blanks_dots : string -> string
|
|
19 |
val no_blanks_dots_dashes : string -> string
|
|
20 |
val no_dots : string -> string
|
|
21 |
val no_rep_add : ''a -> ''a list -> ''a list
|
|
22 |
val no_rep_app : ''a list -> ''a list -> ''a list
|
|
23 |
val pair_ins : 'a -> 'b list -> ('a * 'b) list
|
|
24 |
val rm_rep : ''a list -> ''a list
|
|
25 |
val write_strs : TextIO.outstream -> TextIO.vector list -> unit
|
|
26 |
val writeln_strs : TextIO.outstream -> TextIO.vector list -> unit
|
15347
|
27 |
|
|
28 |
end;
|
|
29 |
|
|
30 |
|
|
31 |
structure ResLib : RES_LIB =
|
|
32 |
struct
|
|
33 |
|
15604
|
34 |
(* convert a list of strings into one single string; surrounded by brackets *)
|
|
35 |
fun list_to_string strings =
|
|
36 |
let
|
|
37 |
fun str_of [s] = s
|
|
38 |
| str_of (s1::ss) = s1 ^ "," ^ (str_of ss)
|
|
39 |
| str_of _ = ""
|
|
40 |
in
|
|
41 |
"(" ^ str_of strings ^ ")"
|
|
42 |
end;
|
15347
|
43 |
|
15604
|
44 |
fun list_to_string' strings =
|
|
45 |
let
|
|
46 |
fun str_of [s] = s
|
|
47 |
| str_of (s1::ss) = s1 ^ "," ^ (str_of ss)
|
|
48 |
| str_of _ = ""
|
|
49 |
in
|
|
50 |
"[" ^ str_of strings ^ "]"
|
|
51 |
end;
|
15347
|
52 |
|
15604
|
53 |
(* remove some chars (not allowed by TPTP format) from a string *)
|
|
54 |
fun no_blanks " " = "_"
|
|
55 |
| no_blanks c = c;
|
15347
|
56 |
|
15604
|
57 |
fun no_dots "." = "_dot_"
|
|
58 |
| no_dots c = c;
|
15347
|
59 |
|
15604
|
60 |
fun no_blanks_dots " " = "_"
|
|
61 |
| no_blanks_dots "." = "_dot_"
|
|
62 |
| no_blanks_dots c = c;
|
15347
|
63 |
|
15604
|
64 |
fun no_blanks_dots_dashes " " = "_"
|
|
65 |
| no_blanks_dots_dashes "." = "_dot_"
|
|
66 |
| no_blanks_dots_dashes "'" = "_da_"
|
|
67 |
| no_blanks_dots_dashes c = c;
|
15347
|
68 |
|
15604
|
69 |
fun no_BDD cs =
|
|
70 |
implode (map no_blanks_dots_dashes (explode cs));
|
15347
|
71 |
|
15604
|
72 |
fun no_rep_add x [] = [x]
|
|
73 |
| no_rep_add x (y::z) = if x=y then y::z else y::(no_rep_add x z);
|
15347
|
74 |
|
15604
|
75 |
fun no_rep_app l1 [] = l1
|
|
76 |
| no_rep_app l1 (x::y) = no_rep_app (no_rep_add x l1) y;
|
15347
|
77 |
|
15604
|
78 |
fun rm_rep [] = []
|
|
79 |
| rm_rep (x::y) = if x mem y then rm_rep y else x::(rm_rep y);
|
15347
|
80 |
|
15604
|
81 |
fun flat_noDup [] = []
|
|
82 |
| flat_noDup (x::y) = no_rep_app x (flat_noDup y);
|
15347
|
83 |
|
15604
|
84 |
fun list2str_sep delim [] = delim
|
|
85 |
| list2str_sep delim (s::ss) = (s ^ delim) ^ (list2str_sep delim ss);
|
15347
|
86 |
|
15604
|
87 |
fun write_strs _ [] = ()
|
|
88 |
| write_strs out (s::ss) = (TextIO.output (out, s); write_strs out ss);
|
15347
|
89 |
|
15604
|
90 |
fun writeln_strs _ [] = ()
|
|
91 |
| writeln_strs out (s::ss) = (TextIO.output (out, s); TextIO.output (out, "\n"); writeln_strs out ss);
|
15347
|
92 |
|
15604
|
93 |
(* pair the first argument with each element in the second input list *)
|
|
94 |
fun pair_ins x [] = []
|
|
95 |
| pair_ins x (y::ys) = (x, y) :: (pair_ins x ys);
|
15347
|
96 |
|
15604
|
97 |
end;
|