ocaml: phase 5.1 grep_count.ml baseline (substring-aware line filter, 3 matches)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 27s

Defines a recursive str_contains that walks the haystack with
String.sub to find a needle substring. Real OCaml's String.contains
only accepts a single char, so this baseline implements its own
substring search to stay portable.

  let rec str_contains s sub i =
    if i + sl > nl then false
    else if String.sub s i sl = sub then true
    else str_contains s sub (i + 1)

count_matching splits text on newlines, folds with the predicate.

  'the quick brown fox\nfox runs fast\nthe dog\nfoxes are clever'
   needle = 'fox'
   matches = 3 (lines 1, 2, 4 — 'foxes' contains 'fox')

43 baseline programs total.
This commit is contained in:
2026-05-09 09:34:40 +00:00
parent b0cbdaf713
commit 3be2dc6e78
3 changed files with 25 additions and 0 deletions

View File

@@ -407,6 +407,13 @@ _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 — grep_count.ml baseline (substring-aware
line filter, 3 lines match). Defines a recursive `str_contains`
that walks the haystack with `String.sub` slices to find a needle
substring (real OCaml's `String.contains` only takes a char).
Splits text on `'\n'` then folds with the contains predicate. Test
text has 4 lines, 3 contain 'fox' (incl 'foxes'). 43 baseline
programs total.
- 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