js-maker simpeler

This commit is contained in:
2026-06-08 12:15:04 +02:00
parent cffb5ec91a
commit a9610e6e0c
5 changed files with 92 additions and 1003 deletions
+11 -1
View File
@@ -173,9 +173,13 @@
;; First evaluate all RHS expressions into temporary names.
;; This preserves ordinary Racket/Scheme `let` scoping:
;; newly bound names are not visible to other RHS expressions.
;; The real bindings are introduced in an inner block so
;; JavaScript `let` TDZ rules do not shadow RHS references.
(string-append "const " (js-id tmp) " = " (js1 init) ";\n") ...
"{\n"
(string-append "let " (js-id id) " = " (js-id tmp) ";\n") ...
(js body ...)
"}\n"
"}"))]))
;; -------------------------------------------------------------------------
@@ -235,11 +239,15 @@
#'(string-append "{\n"
;; Initial expressions are evaluated before the loop
;; variables are introduced, like named `let` in Racket.
;; The loop variables live in an inner block for the same
;; reason as ordinary `let`: avoid JavaScript TDZ shadowing.
(string-append "const " (js-id tmp) " = " (js1 init) ";\n") ...
"{\n"
(string-append "let " (js-id id) " = " (js-id tmp) ";\n") ...
"while (true) {\n"
(js-loop-tail loop-name (id ...) body ...)
"}\n"
"}\n"
"}"))]))
;; -------------------------------------------------------------------------
@@ -248,7 +256,7 @@
;; -------------------------------------------------------------------------
(define-syntax (js1 stx)
(syntax-case stx ()
(syntax-case stx (define lambda λ if set! let let* begin return quote eval)
[(_ (define (f arg ...) body ...)) #'(js-define-function f (arg ...) body ...)]
[(_ (define name expr)) #'(js-define-value name expr)]
[(_ (lambda (arg ...) body ...)) #'(js-lambda (arg ...) body ...)]
@@ -300,6 +308,8 @@
[(_ statement ...)
(string-append (js-stmt (js1 statement)) ...)]))
;; -------------------------------------------------------------------------
;; Examples
;; -------------------------------------------------------------------------