[plt-scheme] Macro expanding into define-values/invoke-unit?
This is because of hygiene and the way define-values/invoke-unit
introduces bindings (it inherits the lexical information of either
itself or it's arguments).
I don't have time to look into the way define-values/invoke-unit expands
now, but a quick solution works:
#lang scheme
(define-signature foo^ (bar))
(define-unit foo@
(import)
(export foo^)
(define (bar x) (* x x)))
(define-syntax (mkfoo stx)
(syntax-case stx ()
[(_ x)
(datum->syntax #'x
`(define-values/invoke-unit ,#'x (import) (export
foo^)))]))
(mkfoo foo@)
(bar 3)
-
Chongkai
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
>