[plt-scheme] Binding transformers in a macro

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Oct 23 12:27:16 EDT 2008

At Thu, 23 Oct 2008 17:13:20 +0100, "Noel Welsh" wrote:
> Oh Great Gods of Syntax Transformation!

They've never answered me...

> I thought I could define imports using the following piece of code:
> 
> (define-for-syntax (make-define-form import-id real-import-id context)
>   (if (transformer? real-import-id)
>       (let ([transformer (syntax-local-value real-import-id)])
>         (datum->syntax context
>                        `(define-syntax ,import-id ,transformer)))
>       (datum->syntax context
>                      `(define ,import-id ,real-import-id))))
> 
> But alas!  I get an error:
> 
> compile: bad syntax; literal data is not allowed, because no #%datum
> syntax transformer is bound in: #<procedure:...e/more-scheme.ss:90:4>

The immediate problem is that you're using `context' to get the lexical
context, but the syntax object bound to `context' doesn't have a
`(require (for-syntax scheme/base))' in its context.

Why not just

 #`(define-syntax #,import-id #,transformer)

?

Also, 3-D syntax (injecting the procedure bound to `transformer') is
probably a bad idea. If I understand, then

 #`(define-syntax #,import-id (make-rename-transformer #'#,real-import-id))

is probably better.


You meant `(macro-foo)' and not `(foo)' at the end of your test, right?



Posted on the users mailing list.