[plt-scheme] Macro expanding into define-values/invoke-unit?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Jul 12 22:57:48 EDT 2009

The `foo^' signature introduced by the macro acts like a binding
identifier introduced by a macro: It doesn't bind other identifiers
unless they are introduced by the same macro expansion.

One solution is to provide the signature name, so that it isn't
introduced by the macro:

 (define-syntax mkfoo
   (syntax-rules ()
     [(_ x foo^) (define-values/invoke-unit x (import) (export foo^))]))

 (mkfoo foo@ foo^)

At Sun, 12 Jul 2009 17:11:00 -0400, Anthony Cowley wrote:
> How can I get a macro to expand into a (define-values/invoke-unit ...)
> form? That is, I have a macro that constructs syntax that looks
> correct, but is left unexpanded before the rest of the module
> containing my macro invocation is expanded. I think the below
> demonstrates the issue. When run, the module produces the value 9, but
> if the "Works!" line is commented out, while the following line is
> uncommented, then "bar" is an unbound identifier. In my case, my macro
> lives in another module, so if there are some phase gymnastics needed,
> that would be fine, but I haven't been able to discover them yet.
> Thanks,
> Anthony
> #lang scheme
> (define-signature foo^ (bar))
> (define-unit foo@
>   (import)
>   (export foo^)
>   (define (bar x) (* x x)))
> (define-syntax mkfoo
>   (syntax-rules ()
>     [(_ x) (define-values/invoke-unit x (import) (export foo^))]))
> (define-values/invoke-unit foo@ (import) (export foo^)) ; Works!
> ;(mkfoo foo@) ; Doesn't work!
> (bar 3)
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.