src/Pure/POLY.ML
author clasohm
Fri Oct 22 13:39:23 1993 +0100 (1993-10-22 ago)
changeset 73 075db6ac7f2f
parent 66 1b14cd923772
child 100 e95b98536b3d
permissions -rw-r--r--
delete_file now has type string -> unit in both NJ and POLY,
use of Pure/Thy/ROOT has been moved to the end of Pure/ROOT again
clasohm@0
     1
(*  Title:      Pure/POLY
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1991  University of Cambridge
clasohm@0
     5
clasohm@0
     6
Compatibility file for Poly/ML (AHL release 1.88)
clasohm@0
     7
*)
clasohm@0
     8
clasohm@0
     9
open PolyML ExtendedIO;
clasohm@0
    10
clasohm@0
    11
clasohm@0
    12
(*A conditional timing function: applies f to () and, if the flag is true,
clasohm@0
    13
  prints its runtime.*)
clasohm@0
    14
clasohm@0
    15
fun cond_timeit flag f =
clasohm@0
    16
  if flag then
clasohm@0
    17
    let val before = System.processtime()
clasohm@0
    18
        val result = f()
clasohm@0
    19
        val both = real(System.processtime() - before) / 10.0
clasohm@0
    20
    in  output(std_out, "Process time (incl GC): "^
clasohm@0
    21
                         makestring both ^ " secs\n");
clasohm@0
    22
        result
clasohm@0
    23
    end
clasohm@0
    24
  else f();
clasohm@0
    25
clasohm@0
    26
clasohm@0
    27
(*Save function: in Poly/ML, ignores filename and commits to present file*)
clasohm@0
    28
clasohm@0
    29
fun xML filename banner = commit();
clasohm@0
    30
clasohm@0
    31
clasohm@0
    32
(*Interface for toplevel pretty printers, see also Pure/install_pp.ML*)
clasohm@0
    33
clasohm@0
    34
fun make_pp _ pprint (str, blk, brk, en) obj =
wenzelm@19
    35
  pprint obj (str, fn ind => blk (ind, false), fn wd => brk (wd, 0),
wenzelm@19
    36
    fn () => brk (99999, 0), en);
clasohm@0
    37
clasohm@0
    38
lcp@66
    39
(*** File handling ***)
clasohm@0
    40
clasohm@58
    41
(*Get a string containing the time of last modification, attributes, owner
clasohm@58
    42
  and size of file (but not the path) *)
clasohm@0
    43
fun file_info "" = ""
clasohm@0
    44
  | file_info name =
clasohm@58
    45
      let
clasohm@58
    46
          (*These are functions from library.ML *)
clasohm@58
    47
          fun take_suffix _ [] = ([], [])
clasohm@58
    48
            | take_suffix pred (x :: xs) =
clasohm@58
    49
                (case take_suffix pred xs of
clasohm@58
    50
                  ([], sffx) => if pred x then ([], x :: sffx) else ([x], sffx)
clasohm@58
    51
                | (prfx, sffx) => (x :: prfx, sffx));
clasohm@58
    52
          fun apr (f,y) x = f(x,y);
clasohm@0
    53
clasohm@58
    54
          val (is, os) = ExtendedIO.execute ("ls -l " ^ name)
clasohm@58
    55
          val (result, _) = take_suffix (apr(op<>," ")) 
clasohm@58
    56
                              (explode (ExtendedIO.input_line is))
lcp@66
    57
             (*Remove the part after the last " " (i.e. the path/filename) *)
clasohm@58
    58
        in close_in is;
clasohm@58
    59
           close_out os;
clasohm@58
    60
           implode result
clasohm@58
    61
        end;
lcp@66
    62
clasohm@73
    63
(*Delete a file *)
clasohm@73
    64
fun delete_file name =
clasohm@73
    65
  let val (_,_) = ExtendedIO.execute ("rm " ^ name)
clasohm@73
    66
  in () end;