From d8f1882b505ef7b91e5cc665bc49f37d2c7fd0b3 Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 8 May 2026 17:44:07 +0000 Subject: [PATCH] ocaml: phase 5.1 fizzbuzz.ml baseline (12/12 pass) Classic fizzbuzz using ref-cell accumulator, for-loop, mod, if/elseif chain, String.concat, Int.to_string. Output verified via String.length of the comma-joined result for n=15: 57. --- lib/ocaml/baseline/expected.json | 1 + lib/ocaml/baseline/fizzbuzz.ml | 17 +++++++++++++++++ plans/ocaml-on-sx.md | 3 +++ 3 files changed, 21 insertions(+) create mode 100644 lib/ocaml/baseline/fizzbuzz.ml diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 98764167..f277cca4 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -4,6 +4,7 @@ "exception_handle.ml": 4, "expr_eval.ml": 16, "factorial.ml": 3628800, + "fizzbuzz.ml": 57, "list_ops.ml": 30, "module_use.ml": 3, "option_match.ml": 5, diff --git a/lib/ocaml/baseline/fizzbuzz.ml b/lib/ocaml/baseline/fizzbuzz.ml new file mode 100644 index 00000000..86933c01 --- /dev/null +++ b/lib/ocaml/baseline/fizzbuzz.ml @@ -0,0 +1,17 @@ +(* Baseline: fizzbuzz returning a list of strings *) +let fizzbuzz n = + let acc = ref [] in + for i = 1 to n do + let s = + if i mod 15 = 0 then "FizzBuzz" + else if i mod 3 = 0 then "Fizz" + else if i mod 5 = 0 then "Buzz" + else Int.to_string i + in + acc := s :: !acc + done ; + List.rev !acc +;; + +(* Concatenated for a deterministic check value via String.length *) +String.length (String.concat "," (fizzbuzz 15)) diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 6059f979..6e3dc860 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -399,6 +399,9 @@ _Newest first._ recognise `!` as the prefix-deref of an application argument, so `String.concat "" (List.rev !b)` parses as `(... (deref b))`. Buffer uses a ref holding a string list; contents reverses and concats. +- 2026-05-08 Phase 5.1 — fizzbuzz.ml baseline (12/12 pass). Classic + fizzbuzz using ref-cell accumulator, for-loop, mod, if/elseif chain, + String.concat, Int.to_string. Verifies output via String.length. - 2026-05-08 Phase 2+6 — print primitives wired to host `display` (+2 tests, 444 total). `print_string` / `print_endline` / `print_int` / `print_newline` now use SX `display` (no auto-newline) plus an