ocaml: phase 4 top-level 'let f (a, b) = body' tuple-param decl (+3 tests, 559 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 46s

parse-decl-let lives in the outer ocaml-parse-program scope and does
not have access to parse-pattern (which is local to ocaml-parse).
Source-slicing approach instead:

  1. detect '(IDENT, ...)' in collect-params
  2. scan tokens to the matching ')' (tracking nested parens)
  3. slice the pattern source string from src
  4. push (synth_name, pat_src) onto tuple-srcs

Then after collecting params, the rhs source string gets wrapped with
'match SN with PAT_SRC -> (RHS_SRC)' for each tuple-param,
innermost-first, and the final string is fed through ocaml-parse.

End result is the same AST shape as the iteration-102 inner-let
case: a function whose body destructures a synthetic name.

  let f (a, b) = a + b ;; f (3, 7)            = 10
  let g x (a, b) = x + a + b ;; g 1 (2, 3)    = 6
  let h (a, b) (c, d) = a * b + c * d
  ;; h (1, 2) (3, 4)                          = 14
This commit is contained in:
2026-05-09 04:51:11 +00:00
parent b526d81a4c
commit 82ffc695a5
3 changed files with 78 additions and 3 deletions

View File

@@ -1388,6 +1388,14 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 5132)
(eval "(ocaml-run \"let h (a, b) (c, d) = a * b + c * d in h (1, 2) (3, 4)\")")
;; ── top-level let f (a, b) = body — tuple param decl ──────────
(epoch 5140)
(eval "(ocaml-run-program \"let f (a, b) = a + b ;; f (3, 7)\")")
(epoch 5141)
(eval "(ocaml-run-program \"let g x (a, b) = x + a + b ;; g 1 (2, 3)\")")
(epoch 5142)
(eval "(ocaml-run-program \"let h (a, b) (c, d) = a * b + c * d ;; h (1, 2) (3, 4)\")")
EPOCHS
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -2206,6 +2214,11 @@ check 5130 "let f (a, b) = a + b" '10'
check 5131 "let g x (a, b) mixed" '6'
check 5132 "let h (a, b) (c, d) curried" '14'
# ── top-level let f (a, b) = body — tuple param decl ────────────
check 5140 "top let f (a, b) = a+b" '10'
check 5141 "top let g x (a, b) mixed" '6'
check 5142 "top let h (a, b) (c, d)" '14'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"