ocaml: phase 6 Array module + (op) operator sections (+6 tests, 512 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s

Array module (runtime.sx, OCaml syntax):
  Backed by a 'ref of list'. make/length/get/init build the cell;
  set rewrites the underlying list with one cell changed (O(n) but
  works for short arrays in baseline programs). Includes
  iter/iteri/map/mapi/fold_left/to_list/of_list/copy/blit/fill.

(op) operator sections (parser.sx, parse-atom):
  When the token after '(' is a binop (any op with non-zero
  precedence in the binop table) and the next token is ')', emit
  (:fun ('a' 'b') (:op OP a b)) — i.e. (+)  becomes fun a b -> a + b.
  Recognises every binop including 'mod', 'land', '^', '@', '::',
  etc.

Lets us write:
  List.fold_left (+) 0 [1;2;3;4;5]    = 15
  let f = ( * ) in f 6 7              = 42
  List.map ((-) 10) [1;2;3]           = [9;8;7]
  let a = Array.make 5 7 in
  Array.set a 2 99;
  Array.fold_left (+) 0 a             = 127
This commit is contained in:
2026-05-09 01:59:13 +00:00
parent 5618dd1ef5
commit 1ed3216ba6
4 changed files with 96 additions and 0 deletions

View File

@@ -407,6 +407,16 @@ _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 6 — Array module (ref-of-list backing) + (op)
operator sections (+6 tests, 512 total). Array implements
make/length/get/set/init/iter/iteri/map/mapi/fold_left/to_list/
of_list/copy/blit/fill in OCaml syntax in runtime.sx; backing is a
`ref of list` so set is O(n) but mutation works. (op) sections in
parse-atom: when the token after `(` is a binop and the next is
`)`, emit `(:fun ("a" "b") (:op OP a b))` — `(+)` becomes `fun a b
-> a + b`. Recognises any binop in the precedence table including
`mod`, `land`, `^`, `@`, `::`, etc. Lets us write `List.fold_left
(+) 0 xs` and `((-) 10)` partial applications.
- 2026-05-09 Phase 5.1 — csv.ml baseline (split on '\n' then ',',
parse-int the second field, fold-left). Exercises char escapes
inside string literals, two-stage String.split_on_char, mixed