From 9bc877d781b988768c79d40a0f6a7055e9ad14e7 Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Sat, 9 Aug 2025 01:17:24 +0200 Subject: Register map --- common.sml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'common.sml') diff --git a/common.sml b/common.sml index f8adede..7ed59c3 100644 --- a/common.sml +++ b/common.sml @@ -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 -- cgit v1.2.3