diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 0449c025..1980bab3 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -157,6 +157,7 @@ "tic_tac_toe.ml": 1, "topo_dfs.ml": 24135, "topo_sort.ml": 6, + "wildcard_match.ml": 6, "word_freq.ml": 8, "xor_cipher.ml": 601, "zerosafe.ml": 28, diff --git a/lib/ocaml/baseline/wildcard_match.ml b/lib/ocaml/baseline/wildcard_match.ml new file mode 100644 index 00000000..3ee39e6b --- /dev/null +++ b/lib/ocaml/baseline/wildcard_match.ml @@ -0,0 +1,24 @@ +let rec is_match s i p j = + if j = String.length p then i = String.length s + else if p.[j] = '*' then + is_match s i p (j + 1) + || (i < String.length s && is_match s (i + 1) p j) + else + i < String.length s + && (p.[j] = '?' || p.[j] = s.[i]) + && is_match s (i + 1) p (j + 1) + +let count_match patterns texts = + let count = ref 0 in + List.iter (fun p -> + List.iter (fun t -> + if is_match t 0 p 0 then count := !count + 1 + ) texts + ) patterns; + !count + +;; + +let patterns = ["a*b"; "?b*c"; "*x*y*"] in +let texts = ["aaab"; "abc"; "abxyz"; "xy"; "xyz"; "axby"] in +count_match patterns texts diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index c7be4450..ffe73ce7 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -407,6 +407,17 @@ _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-11 Phase 5.1 — wildcard_match.ml baseline (recursive `*` + /`?` wildcard matcher; over 3×6 = 18 (pattern, text) combos, + 6 match). Cases: + a*b — 1 match (aaab) + ?b*c — 1 match (abc) + *x*y* — 4 matches (abxyz, xy, xyz, axby) + is_match uses `||` for the `*` alternation (consume zero or one + more char and recurse) and `&&` for the literal/`?` case. + Tests deeply nested short-circuit, char equality in pattern + predicate, doubly-nested `List.iter` to enumerate the cross + product. 173 baseline programs total. - 2026-05-11 Phase 5.1 — powerset_target.ml baseline (count subsets of {1..10} summing to 15 = 20). Generates the full 2^10 = 1024 powerset by recursive doubling: `gen (h :: rest) = gen rest @