Actually, here's a more twisted test case with lots of shadowing of
names with different values at different levels:
(use riaxpander)
(define-macro (my-assert test error)
`(if (not ,test) (error ,error)))
(define-syntax foo
(syntax-rules ()
((_ x) (let ((tmp x)) (my-assert tmp "failed")))))
(macroexpand '(let ((x 1) (tmp 2)) (foo (+ x tmp))))
This expands (IMHO correctly) to:
((lambda (x#0 tmp#1) ((lambda (tmp#2) (if (not tmp#2) (error
"failed"))) (+ x#0 tmp#1))) 1 2)
On a side note, it's illuminating to see how redefining 'if' breaks
my-assert (since it's a dirty macro), but even if I put an if into
the foo macro, it doesn't get broken, thanks to the hygienic renaming:
(define-syntax foo
(syntax-rules ()
((_ x) (let ((tmp x)) (if #t (my-assert tmp "failed"))))))
(macroexpand '(let ((if 3) (x 1) (tmp 2)) (foo (+ x tmp))))
produces:
((lambda (if#0 x#1 tmp#2) ((lambda (tmp#3) (if #t (if#0 (not tmp#3)
(error "failed")))) (+ x#1 tmp#2))) 3 1 2)
Note how my rebinding of if becomes if#0, while foo still refers to
plain old if, but the expanded body of assert picks up if#0.
ABS
--
Alaric Snell-Pym
Work: http://www.snell-systems.co.uk/
Play: http://www.snell-pym.org.uk/alaric/
Blog: http://www.snell-pym.org.uk/?author=4
_______________________________________________
Chicken-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-users