|
|
1.1 ! root 1: (* Copyright 1989 by AT&T Bell Laboratories *) ! 2: structure PrintUtil : PRINTUTIL = struct ! 3: ! 4: structure Symbol : SYMBOL = Symbol ! 5: ! 6: fun newline () = print "\n" ! 7: fun tab 0 = () | tab n = (print " "; tab(n-1)) ! 8: ! 9: fun printSequence (separator: string) pr elems = ! 10: let fun prElems [el] = pr el ! 11: | prElems (el::rest) = (pr el; print separator; prElems rest) ! 12: | prElems [] = () ! 13: in prElems elems ! 14: end ! 15: ! 16: fun printClosedSequence (front: string, sep, back:string) pr elems = ! 17: (print front; printSequence sep pr elems; print back) ! 18: ! 19: fun printSym(s: Symbol.symbol) = print(Symbol.name s) ! 20: (* fix -- maybe this belongs in Symbol *) ! 21: ! 22: fun formatQid p = ! 23: let fun f [s] = [Symbol.name s] ! 24: | f (a::r) = Symbol.name a :: "." :: f r ! 25: in implode(f p) ! 26: end ! 27: ! 28: val stringDepth = System.Control.Print.stringDepth ! 29: local ! 30: fun decimal i = let val m = Integer.makestring ! 31: in m(i div 100)^m((i div 10)mod 10)^m(i mod 10) end ! 32: val ctrl_a = 1 ! 33: val ctrl_z = 26 ! 34: val offset = ord "A" - ctrl_a ! 35: val smallestprintable = ord " " ! 36: val biggestprintable = ord "~" ! 37: fun ml_char "\n" = "\\n" ! 38: | ml_char "\t" = "\\t" ! 39: | ml_char "\\" = "\\\\" ! 40: | ml_char "\"" = "\\\"" ! 41: | ml_char c = ! 42: let val char = ord c ! 43: in if char >= ctrl_a andalso char <= ctrl_z ! 44: then "\\^" ^ chr(char+offset) ! 45: else if char >= smallestprintable andalso char <= biggestprintable ! 46: then c ! 47: else "\\" ^ decimal char ! 48: end ! 49: in ! 50: fun mlstr s = "\"" ^ implode(map ml_char (explode s)) ^ "\"" ! 51: fun pr_mlstr s = ! 52: let val depth = !stringDepth ! 53: fun pr i = ! 54: if i=depth then print "#" ! 55: else (let val ch = substring(s,i,1) ! 56: in print(ml_char ch); pr (i+1) ! 57: end handle Substring => ()) ! 58: in print "\""; pr 0; print "\"" ! 59: end ! 60: ! 61: fun nlindent n = (newline(); tab n) ! 62: ! 63: fun printvseq ind (sep:string) pr elems = ! 64: let fun prElems [el] = pr el ! 65: | prElems (el::rest) = (pr el; nlindent ind; print sep; prElems rest) ! 66: | prElems [] = () ! 67: in prElems elems ! 68: end ! 69: ! 70: end (* local *) ! 71: ! 72: end (* structure PrintUtil *)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.