author | paulson |
Tue, 20 Sep 2005 18:43:39 +0200 | |
changeset 17525 | ae5bb6001afb |
parent 17488 | 67376a311a2b |
child 17764 | fde495b9e24b |
permissions | -rw-r--r-- |
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 |
|
16515
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
11 |
val flat_noDup : ''a list list -> ''a list |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
12 |
val helper_path : string -> string -> string |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
13 |
val list2str_sep : string -> string list -> string |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
14 |
val no_rep_add : ''a -> ''a list -> ''a list |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
15 |
val no_rep_app : ''a list -> ''a list -> ''a list |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
16 |
val pair_ins : 'a -> 'b list -> ('a * 'b) list |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
17 |
val write_strs : TextIO.outstream -> TextIO.vector list -> unit |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
18 |
val writeln_strs : TextIO.outstream -> TextIO.vector list -> unit |
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17305
diff
changeset
|
19 |
val intOfPid : Posix.Process.pid -> Int.int |
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17305
diff
changeset
|
20 |
val pidOfInt : Int.int -> Posix.Process.pid |
15347 | 21 |
end; |
22 |
||
23 |
||
24 |
structure ResLib : RES_LIB = |
|
25 |
struct |
|
26 |
||
16515
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
27 |
fun no_rep_add x [] = [x] |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
28 |
| no_rep_add x (y::z) = if x=y then y::z else y::(no_rep_add x z); |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
29 |
|
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
30 |
fun no_rep_app l1 [] = l1 |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
31 |
| no_rep_app l1 (x::y) = no_rep_app (no_rep_add x l1) y; |
15347 | 32 |
|
16515
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
33 |
fun flat_noDup [] = [] |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
34 |
| flat_noDup (x::y) = no_rep_app x (flat_noDup y); |
15347 | 35 |
|
16515
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
36 |
fun list2str_sep delim [] = delim |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
37 |
| list2str_sep delim (s::ss) = (s ^ delim) ^ (list2str_sep delim ss); |
15347 | 38 |
|
16515
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
39 |
fun write_strs _ [] = () |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
40 |
| write_strs out (s::ss) = (TextIO.output (out, s); write_strs out ss); |
15347 | 41 |
|
16515
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
42 |
fun writeln_strs _ [] = () |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
43 |
| writeln_strs out (s::ss) = (TextIO.output (out, s); TextIO.output (out, "\n"); writeln_strs out ss); |
15347 | 44 |
|
16515
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
45 |
(* pair the first argument with each element in the second input list *) |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
46 |
fun pair_ins x [] = [] |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
47 |
| pair_ins x (y::ys) = (x, y) :: (pair_ins x ys); |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
48 |
|
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
49 |
(*Return the path to a "helper" like SPASS or tptp2X, first checking that |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
50 |
it exists. --lcp *) |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
51 |
fun helper_path evar base = |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
52 |
case getenv evar of |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
53 |
"" => error ("Isabelle environment variable " ^ evar ^ " not defined") |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
54 |
| home => |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
55 |
let val path = home ^ "/" ^ base |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
56 |
in if File.exists (File.unpack_platform_path path) then path |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
57 |
else error ("Could not find the file " ^ path) |
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
paulson
parents:
15774
diff
changeset
|
58 |
end; |
15347 | 59 |
|
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17305
diff
changeset
|
60 |
(*** Converting between process ids and integers ***) |
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17305
diff
changeset
|
61 |
|
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17305
diff
changeset
|
62 |
fun intOfPid pid = Word.toInt (Word.fromLargeWord (Posix.Process.pidToWord pid)); |
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17305
diff
changeset
|
63 |
|
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17305
diff
changeset
|
64 |
fun pidOfInt n = Posix.Process.wordToPid (Word.toLargeWord (Word.fromInt n)); |
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17305
diff
changeset
|
65 |
|
15604 | 66 |
end; |