diff --git a/lib/ocaml/eval.sx b/lib/ocaml/eval.sx index d91e522b..ca12fdda 100644 --- a/lib/ocaml/eval.sx +++ b/lib/ocaml/eval.sx @@ -72,10 +72,11 @@ (list "_string_of_float" (fn (f) (str f))) (list "_char_code" (fn (c) (char-code c))) (list "_char_chr" (fn (n) (char-from-code n))) - ;; Print: prints to host stdout via println. - (list "print_string" (fn (s) (begin (print s) nil))) - (list "print_endline" (fn (s) (begin (println s) nil))) - (list "print_int" (fn (i) (begin (print (str i)) nil))) + ;; Print: route to host SX `display` (no automatic newline). + (list "print_string" (fn (s) (begin (display s) nil))) + (list "print_endline" (fn (s) (begin (display s) (display "\n") nil))) + (list "print_int" (fn (i) (begin (display (str i)) nil))) + (list "print_newline" (fn (_) (begin (display "\n") nil))) ;; Float math primitives. (list "_float_sqrt" (fn (x) (sqrt x))) (list "_float_sin" (fn (x) (sin x))) diff --git a/lib/ocaml/test.sh b/lib/ocaml/test.sh index c7345ac0..3c5f2114 100755 --- a/lib/ocaml/test.sh +++ b/lib/ocaml/test.sh @@ -1092,6 +1092,12 @@ cat > "$TMPFILE" << 'EPOCHS' (epoch 3802) (eval "(ocaml-type-of \"let f x = x + 1 and g x = x * 2 in f 1 + g 2\")") +;; ── let _ = expr top-level ───────────────────────────────────── +(epoch 3900) +(eval "(ocaml-run-program \"let _ = 1 + 2 ;; 42\")") +(epoch 3901) +(eval "(ocaml-run-program \"let x = 10 ;; let _ = x ;; x * 2\")") + EPOCHS OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null) @@ -1728,6 +1734,10 @@ check 3800 "let-mut x+y : Int" '"Int"' check 3801 "let-rec-mut even" '"Int -> Bool"' check 3802 "let-mut f and g" '"Int"' +# ── let _ = expr top-level ───────────────────────────────────── +check 3900 "let _ = 1+2;; 42" '42' +check 3901 "two top-level lets, _" '20' + TOTAL=$((PASS + FAIL)) if [ $FAIL -eq 0 ]; then echo "ok $PASS/$TOTAL OCaml-on-SX tests passed" diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 07a57fac..6059f979 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -399,6 +399,13 @@ _Newest first._ recognise `!` as the prefix-deref of an application argument, so `String.concat "" (List.rev !b)` parses as `(... (deref b))`. Buffer uses a ref holding a string list; contents reverses and concats. +- 2026-05-08 Phase 2+6 — print primitives wired to host `display` (+2 + tests, 444 total). `print_string` / `print_endline` / `print_int` / + `print_newline` now use SX `display` (no auto-newline) plus an + explicit `"\n"` for endline. Prior version referenced `print`/ + `println` host primitives that don't exist. `let _ = expr ;;` + top-level decl works as expected (already supported by the + wildcard-param parser). - 2026-05-08 Phase 5 — HM let-mut / let-rec-mut inference (+3 tests, 442 total). `ocaml-infer-let-mut` infers each rhs in the parent env and generalizes sequentially; `ocaml-infer-let-rec-mut` pre-binds