diff options
Diffstat (limited to 'common.sml')
-rw-r--r-- | common.sml | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -124,6 +124,25 @@ in Fold.fold ((false, makePrintfBase output), finish) end g +fun printfp n g = +let + val buf = ref [] + fun output s = buf := s :: !buf + fun finish _ = + let + val s = String.concat $ rev $ !buf + val s = + if size s < n then + implode (List.tabulate (n - size s, fn _ => #" ")) ^ s + else + s + in + TextIO.output (TextIO.stdOut, s) + end +in + Fold.fold ((false, makePrintfBase output), finish) +end g + fun Printf out g = Fold.fold ((false, out), fn _ => ()) g local @@ -152,6 +171,24 @@ fun F z = bind A0 (fn (_, mf) => mf ()) z val I = fn z => bindWith2str Int.toString z fun i v out = Printf out I v % +val Ip = fn z => +let + fun f w i out = + let + val s = Int.toString i + val len = size s + val s = + if len < w then + implode (List.tabulate (w - len, fn _ => #" ")) ^ s + else + s + in + Printf out `s % + end +in + bind A2 f +end z + val C = fn z => bindWith2str str z val B = fn z => bindWith2str Bool.toString z val W = fn z => bindWith2str (Word.fmt StringCvt.DEC) z |