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