ocaml: phase 2 function | pat -> body (+4 tests, 198 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 54s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 54s
Sugar for fun + match. AST (:function CLAUSES) -> unary closure that runs ocaml-match-clauses on its arg. let rec recognises :function as a recursive rhs and ties the knot via cell, so let rec map f = function | [] -> [] | h::t -> f h :: map f t works. ocaml-match-eval refactored to share clause-walk with function.
This commit is contained in:
@@ -507,6 +507,16 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 624)
|
||||
(eval "(ocaml-run \"let p = ref 1 in for i = 1 to 5 do p := !p * i done; !p\")")
|
||||
|
||||
;; ── function (sugar for fun + match) ───────────────────────────
|
||||
(epoch 640)
|
||||
(eval "(ocaml-run \"(function | None -> 0 | Some x -> x) (Some 7)\")")
|
||||
(epoch 641)
|
||||
(eval "(ocaml-run \"let f = function | None -> 0 | Some x -> x in f None\")")
|
||||
(epoch 642)
|
||||
(eval "(ocaml-run \"let rec len = function | [] -> 0 | _ :: t -> 1 + len t in len [1; 2; 3]\")")
|
||||
(epoch 643)
|
||||
(eval "(ocaml-run-program \"let rec map f = function | [] -> [] | h :: t -> f h :: map f t;; map (fun x -> x * x) [1; 2; 3; 4]\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 60 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -808,6 +818,12 @@ check 622 "while loop" '15'
|
||||
check 623 "for 1..100 sum" '5050'
|
||||
check 624 "for 1..5 product = 120" '120'
|
||||
|
||||
# ── function ────────────────────────────────────────────────────
|
||||
check 640 "function None|Some Some 7" '7'
|
||||
check 641 "function None=0" '0'
|
||||
check 642 "rec function len" '3'
|
||||
check 643 "rec function map x*x" '(1 4 9 16)'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user