From b0cbdaf713c47680c55c908e25ee08ae33ab6566 Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 9 May 2026 09:24:41 +0000 Subject: [PATCH] ocaml: phase 5.1 pretty_table.ml baseline (Buffer + Printf widths, len = 64) Builds a 4-row scoreboard via Buffer + Printf.sprintf: Buffer.add_string buf (Printf.sprintf '%-10s %4d\n' name score) Each row is exactly 16 chars regardless of actual name/score length: 10 name padding + 1 space + 4 score padding + 1 newline. 4 rows -> 64 chars total. Combines: - Buffer.add_string + Printf.sprintf - %-Ns left-justified string and %Nd right-justified int width - List.iter on tuple-pattern args (iter 101 fun (a, b)) 42 baseline programs total. --- lib/ocaml/baseline/expected.json | 1 + lib/ocaml/baseline/pretty_table.ml | 10 ++++++++++ plans/ocaml-on-sx.md | 8 ++++++++ 3 files changed, 19 insertions(+) create mode 100644 lib/ocaml/baseline/pretty_table.ml diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index ee54648f..ae92cffc 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -29,6 +29,7 @@ "mutable_record.ml": 10, "option_match.ml": 5, "pi_leibniz.ml": 314, + "pretty_table.ml": 64, "poly_stack.ml": 5, "queens.ml": 2, "quicksort.ml": 44, diff --git a/lib/ocaml/baseline/pretty_table.ml b/lib/ocaml/baseline/pretty_table.ml new file mode 100644 index 00000000..a3df8e3c --- /dev/null +++ b/lib/ocaml/baseline/pretty_table.ml @@ -0,0 +1,10 @@ +let table rows = + let buf = Buffer.create 64 in + List.iter (fun (name, score) -> + Buffer.add_string buf (Printf.sprintf "%-10s %4d\n" name score) + ) rows; + Buffer.contents buf + +;; + +String.length (table [("alice", 95); ("bob", 67); ("carol", 100); ("dave", 8)]) diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index b767af7c..f4747065 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,14 @@ _Newest first._ binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree * 'a tree`) with insert + in-order traversal. Tests parametric ADT, recursive match, List.append, List.fold_left. +- 2026-05-09 Phase 5.1 — pretty_table.ml baseline (Buffer + Printf + width specifiers, total length 64). Builds a 4-row scoreboard via + Buffer + `Printf.sprintf "%-10s %4d\n"`. Each row is exactly 16 + chars (10 name + 1 space + 4 score + 1 newline) regardless of + actual content length thanks to width padding. 4 rows = 64 chars. + Combines Buffer.add_string + Printf.sprintf with `%-Ns` / + `%Nd` width specifiers + List.iter on tuple-pattern args. 42 + baseline programs total. - 2026-05-09 Phase 4 — bitwise ops `land`/`lor`/`lxor`/`lsl`/`lsr`/ `asr` + bits.ml baseline (popcount-sum = 21) (+5 tests, 607 total). The binop precedence table already had these but eval-op fell