ocaml: phase 6 Hashtbl.keys/values/bindings/remove/clear (+4 tests, 545 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

Two new host primitives:
  _hashtbl_remove t k   -> dissoc the key from the underlying dict
  _hashtbl_clear  t     -> reset the cell to {}

Eight new OCaml-syntax helpers in runtime.sx Hashtbl module:
  bindings t            = _hashtbl_to_list t
  keys t                = List.map (fun (k, _) -> k) (...)
  values t              = List.map (fun (_, v) -> v) (...)
  to_seq t              = bindings t
  to_seq_keys / to_seq_values
  remove / clear / reset

The keys/values implementations use a 'fun pair -> match pair with
(k, _) -> k' indirection because parse-fun does not currently allow
tuple patterns directly on parameters. Same restriction we worked
around in iteration 98's let-pattern desugaring.

Also: a detour attempting to add top-level 'let (a, b) = expr'
support was started but reverted — parse-decl-let in the outer
ocaml-parse-program scope does not have access to parse-pattern
(which is local to ocaml-parse). Will need a slice + re-parse trick
later.
This commit is contained in:
2026-05-09 03:59:20 +00:00
parent dab8718289
commit 41190c6d23
4 changed files with 58 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 — Hashtbl.keys / values / bindings / remove /
clear / reset / to_seq / to_seq_keys / to_seq_values (+4 tests, 545
total). Two new host primitives `_hashtbl_remove` and
`_hashtbl_clear`; the rest are pure OCaml-syntax helpers in
runtime.sx that map over `_hashtbl_to_list`. `keys` and `values`
pattern-match the (k, v) tuples to extract one side. Note: a
detour to also support top-level `let (a, b) = expr` was reverted
— `parse-decl-let` lives in the outer ocaml-parse-program scope
which doesn't have access to parse-pattern; will need a slice +
inner-parse trick later.
- 2026-05-09 Phase 4 — `let PATTERN = expr in body` tuple
destructuring (+3 tests, 541 total). When `let` is followed by `(`,
parse-let now reads a full pattern, expects `=`, then `in`, and