ocaml: phase 5.1 bag.ml baseline + String.equal/compare/cat/empty (+3 tests, 579 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

bag.ml: split a sentence on spaces, count each word in a Hashtbl,
return the maximum count via Hashtbl.fold.

  count_words 'the quick brown fox jumps over the lazy dog the fox'
  -> Hashtbl with 'the' = 3 as the max
  -> 3

Exercises String.split_on_char + Hashtbl.find_opt/replace +
Hashtbl.fold (k v acc -> ...). Together with frequency.ml from
iter 84 we now have two Hashtbl-counting baselines exercising
slightly different idioms. 29 baseline programs total.

String additions:
  equal a b      = a = b
  compare a b    = -1 / 0 / 1 via host < / >
  cat a b        = a ^ b
  empty          = '' (constant)
This commit is contained in:
2026-05-09 06:15:03 +00:00
parent 7ca5bfbb70
commit ddd1e40d00
5 changed files with 45 additions and 0 deletions

View File

@@ -1440,6 +1440,14 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 5193)
(eval "(ocaml-run \"Seq.fold_left (+) 0 (Seq.unfold (fun n -> if n > 4 then None else Some (n, n + 1)) 1)\")")
;; ── String.equal / compare / cat ─────────────────────────────
(epoch 5200)
(eval "(ocaml-run \"String.equal \\\"abc\\\" \\\"abc\\\"\")")
(epoch 5201)
(eval "(ocaml-run \"String.compare \\\"banana\\\" \\\"apple\\\"\")")
(epoch 5202)
(eval "(ocaml-run \"String.cat \\\"hello \\\" \\\"world\\\"\")")
EPOCHS
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -2290,6 +2298,11 @@ check 5191 "Seq filter evens" '5'
check 5192 "Seq init 5 i*2" '20'
check 5193 "Seq unfold 1..4 sum" '10'
# ── String.equal / compare / cat ────────────────────────────────
check 5200 "String.equal abc abc" 'true'
check 5201 "String.compare banana apple" '1'
check 5202 "String.cat hello world" '"hello world"'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"