[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] macro systems and chicken (long)
From: |
Alaric Snell-Pym |
Subject: |
Re: [Chicken-users] macro systems and chicken (long) |
Date: |
Tue, 8 Apr 2008 12:04:45 +0100 |
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
- Re: [Chicken-users] macro systems and chicken (long), (continued)
- Re: [Chicken-users] macro systems and chicken (long), Leonardo Valeri Manera, 2008/04/04
- Re: [Chicken-users] macro systems and chicken (long), felix winkelmann, 2008/04/07
- Re: [Chicken-users] macro systems and chicken (long), Peter Bex, 2008/04/07
- Re: [Chicken-users] macro systems and chicken (long), felix winkelmann, 2008/04/07
- Re: [Chicken-users] macro systems and chicken (long), Jim Ursetto, 2008/04/11
- Re: [Chicken-users] macro systems and chicken (long), Peter Bex, 2008/04/12
- Re: [Chicken-users] macro systems and chicken (long), felix winkelmann, 2008/04/14
- Re: [Chicken-users] macro systems and chicken (long), Alaric Snell-Pym, 2008/04/07
- Re: [Chicken-users] macro systems and chicken (long), felix winkelmann, 2008/04/08
- Re: [Chicken-users] macro systems and chicken (long), Alaric Snell-Pym, 2008/04/08
- Re: [Chicken-users] macro systems and chicken (long),
Alaric Snell-Pym <=
- Re: [Chicken-users] macro systems and chicken (long), felix winkelmann, 2008/04/09
- Re: [Chicken-users] macro systems and chicken (long), Alaric Snell-Pym, 2008/04/12
- Re: [Chicken-users] macro systems and chicken (long), Graham Fawcett, 2008/04/07
- Re: [Chicken-users] macro systems and chicken (long), felix winkelmann, 2008/04/08
- Re: [Chicken-users] macro systems and chicken (long), Alaric Snell-Pym, 2008/04/08
- Re: [Chicken-users] macro systems and chicken (long), felix winkelmann, 2008/04/09
- Re: [Chicken-users] macro systems and chicken (long), Alex Shinn, 2008/04/17
- Re: [Chicken-users] macro systems and chicken (long), Alaric Snell-Pym, 2008/04/17
- Re: [Chicken-users] macro systems and chicken (long), Alex Shinn, 2008/04/17
- Re: [Chicken-users] macro systems and chicken (long), Alaric Snell-Pym, 2008/04/18