3 Author: Lawrence C Paulson, Cambridge University Computer Laboratory
4 Copyright 1991 University of Cambridge
6 Compatibility file for Poly/ML (AHL release 1.88)
9 open PolyML ExtendedIO;
13 (*A conditional timing function: applies f to () and, if the flag is true,
16 fun cond_timeit flag f =
18 let val before = System.processtime()
20 val both = real(System.processtime() - before) / 10.0
21 in output(std_out, "Process time (incl GC): "^
22 makestring both ^ " secs\n");
28 (*Save function: in Poly/ML, ignores filename and commits to present file*)
30 fun xML filename banner = commit();
33 (*Interface for toplevel pretty printers, see also Pure/install_pp.ML*)
35 fun make_pp _ pprint (str, blk, brk, en) obj =
36 pprint obj (str, fn ind => blk (ind, false), fn wd => brk (wd, 0),
37 fn () => brk (99999, 0), en);
40 (*** File handling ***)
44 (*These are functions from library.ML *)
45 fun take_suffix _ [] = ([], [])
46 | take_suffix pred (x :: xs) =
47 (case take_suffix pred xs of
48 ([], sffx) => if pred x then ([], x :: sffx)
50 | (prfx, sffx) => (x :: prfx, sffx));
52 fun apr (f,y) x = f(x,y);
54 fun seq (proc: 'a -> unit) : 'a list -> unit =
56 | seqf (x :: xs) = (proc x; seqf xs)
59 fun radixpand num : int list =
60 let fun radix (n, tail) =
61 if n < 10 then n :: tail else radix (n div 10, (n mod 10) :: tail)
62 in radix (num, []) end;
65 let fun chrof n = chr (ord "0" + n);
66 in implode (map chrof (radixpand num)) end;
70 (*Get time of last modification; if file doesn't exist return an empty string*)
72 | file_info name = radixstring (System.filedate name) handle _ => "";
81 fun remove name = (*Delete a file *)
82 let val (is, os) = ExtendedIO.execute ("rm " ^ name)
83 in close_in is; close_out os end;
85 (*Get pathname of current working directory *)
87 let val (is, os) = ExtendedIO.execute ("pwd")
88 val (path, _) = take_suffix (apr(op=,"\n")) (*remove newline*)
89 (explode (ExtendedIO.input_line is))
90 in close_in is; close_out os; implode path end;
97 (*** ML command execution ***)
100 let fun exec command =
101 let val firstLine = ref true;
105 then (firstLine := false; command)
106 else raise Io "use_string: buffer exhausted"
107 in PolyML.compiler (getLine, fn s => output (std_out, s)) () end
113 (*** System command execution ***)
115 (*Execute an Unix command which doesn't take any input from stdin and
116 sends its output to stdout.*)
117 fun execute command =
118 let val (is, os) = ExtendedIO.execute command;
119 val result = input (is, 999999);
126 (*Non-printing and 8-bit chars are forbidden in string constants*)
127 val needs_filtered_use = true;