js-tranform documentented.

This commit is contained in:
2026-05-16 23:17:59 +02:00
parent 3cb7f56167
commit 18cd4d3bd9
3 changed files with 377 additions and 2 deletions
+36 -2
View File
@@ -281,6 +281,9 @@
(syntax-case stx ()
((_ (a c b1 b2))
(cond
((eq? (syntax->datum #'a) 'define) #'(js-def c (b1 b2)))
((eq? (syntax->datum #'a) 'lambda) #'(js-lambda c b1 b2))
((eq? (syntax->datum #'a) 'λ) #'(js-lambda c b1 b2))
((eq? (syntax->datum #'a) 'if) #'(js2-if c b1 b2))
((memq (syntax->datum #'a) js-ops) #'(js-op a c b1 b2))
((eq? (syntax->datum #'a) 'let*) #'(js2-let* c b1 b2))
@@ -321,6 +324,7 @@
((eq? (syntax->datum #'a) 'return) #'(js-return b))
((eq? (syntax->datum #'a) 'quote) #'(js-quote b))
((eq? (syntax->datum #'a) 'eval) #'(js-eval b))
((eq? (syntax->datum #'a) 'list) #'(js-op a b))
;string-append
; "\"" (esc-double-quote (format "~a" 'b)) "\""))
(else
@@ -334,6 +338,8 @@
(cond
((eq? (syntax->datum #'a) 'let*) #'(js2-let* c b1 ...))
((eq? (syntax->datum #'a) 'define) #'(js-def c (b1 ...)))
((eq? (syntax->datum #'a) 'lambda) #'(js-lambda c b1 ...))
((eq? (syntax->datum #'a) 'λ) #'(js-lambda c b1 ...))
((memq (syntax->datum #'a) js-ops) #'(js-op a c b1 ...))
((eq? (syntax->datum #'a) 'begin) #'(js-begin c b1 ...))
((eq? (syntax->datum #'a) 'let) #'(error "let is not supported in js context, use let*"))
@@ -392,10 +398,11 @@
#|
(define t1
(js (set! window.myfunc (λ (x)
(let* ((el (document.getElementById 'hi))
(let* ((el (send document getElementById 'hi))
(y (* x x)))
(el.setAttribute "x" (+ y ""))
(send el setAttribute "x" (+ y ""))
)
(send console log "dit set attribute x on element hi")
)
)))
@@ -408,6 +415,33 @@
)
)
)
(define t3 (js (define (f x y z)
(send console log (cons x (cons y (list z))))
(let* ((l (cons x (cons y (list z)))))
(return (send l map (λ (a) (return (+ a 10)))))
)
)
)
)
==>
function f(x, y, z) {
console.log([ x].concat([ y].concat([ z])));
{
let l = [ x].concat([ y].concat([ z]));
return (l.map(function (a) { return (a + 10);
;
}
));
;
}
;
}
;
|#