diff options
author | Vladimir Azarov <avm@intermediate-node.net> | 2025-08-09 01:17:24 +0200 |
---|---|---|
committer | Vladimir Azarov <avm@intermediate-node.net> | 2025-08-09 01:17:24 +0200 |
commit | 9bc877d781b988768c79d40a0f6a7055e9ad14e7 (patch) | |
tree | 72ea857d9df1a9dc179e82e1809220013a995606 /common.sml | |
parent | ffee5da4dab26c8500add63da540ee252545370f (diff) |
Register map
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 |