ocaml: phase 4 'let PATTERN = expr in body' tuple destructuring (+3 tests, 541 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 44s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 44s
When 'let' is followed by '(', parse-let now reads a full pattern
(via the existing parse-pattern used by match), expects '=', then
'in', and desugars to:
let PATTERN = EXPR in BODY => match EXPR with PATTERN -> BODY
This reuses the entire pattern-matching machinery, so any pattern
the match parser accepts works here too — paren-tuples, nested
tuples, cons patterns, list patterns. No 'rec' allowed for pattern
bindings (real OCaml's restriction).
let (a, b) = (1, 2) in a + b = 3
let (a, b, c) = (10, 20, 30) in a + b + c = 60
let pair = (5, 7) in
let (x, y) = pair in x * y = 35
Also retroactively cleaned up Printf's iter-97 width-pos packing
hack ('width * 1000000 + spec_pos') — it's now
'let (width, spec_pos) = parse_width_loop after_flags in ...' like
real OCaml.
This commit is contained in:
@@ -407,6 +407,14 @@ _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 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
|
||||
desugars to `(:match expr ((:case PATTERN body)))`. Reuses the
|
||||
pattern parser used by match. `let (a, b, c) = (10, 20, 30) in
|
||||
a+b+c` → 60. Also retroactively cleans up the Printf width-pos
|
||||
packing hack from iteration 97 — it's now `let (width, spec_pos)
|
||||
= parse_width_loop after_flags in ...` like real OCaml.
|
||||
- 2026-05-09 Phase 6 — Printf width specifiers `%5d` / `%-5d` /
|
||||
`%05d` / `%4s` etc. (+5 tests, 538 total). Walker now parses
|
||||
optional `-` (left-align) and `0` (zero-pad) flags after `%`, then
|
||||
|
||||
Reference in New Issue
Block a user