Thanks for the responses. In case anybody is interested, I came up with the following implementation. Since (at least in this simple implementation) there is an obvious symmetry between explicit renaming and implicit renaming I added the er-macro-transformer also. They seem to work correctly. One minor difference to the ir-macro-transformer in Chicken though is that parameters also need to be injected (which kind of logically makes sense).
I am not exactly sure whether datum->syntax and syntax->datum go through the entire expression but if they do, the implementation will be very inefficient. (If anybody knows more on that, I would be interested.) Implementation: #lang racket (provide (for-syntax ir-macro-transformer er-macro-transformer)) (begin-for-syntax (require (for-syntax (only-in racket/base lambda syntax with-syntax))) (define-syntax ir-macro-transformer (lambda (stx) (with-syntax ([(_ proc) stx]) #'(lambda (x) (datum->syntax #'proc (proc (syntax->datum x) (lambda (v) (datum->syntax x v)))))))) (define-syntax er-macro-transformer (lambda (stx) (with-syntax ([(_ proc) stx]) #'(lambda (x) (datum->syntax x (proc (syntax->datum x) (lambda (v) (datum->syntax #'proc v))))))))) Examples: ; loop example from Shu-Hung's post is now working as expected (define-syntax loop (ir-macro-transformer (lambda (expr inject) (let ((body (cdr expr))) `(call-with-current-continuation (lambda (,(inject 'exit)) (let f () (begin .,(inject body)) (f)))))))) ; notice the (inject body) here... dropping the inject will break the code ;=> 543210 ; the following suggests that the lexical environments work as they should (let ([x 1] [y 2]) (swap! x y) x) => 2 (define t 3) (define-syntax tripple (ir-macro-transformer (lambda (expr inject) (let ([a (cadr expr)]) `(* t ,(inject a)))))) (let ([t 29] [* -]) (tripple 2)) ;=> 6 -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.