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

From: Anthony Cowley (acowley at seas.upenn.edu)
Date: Sun Jul 12 17:11:00 EDT 2009

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)


Posted on the users mailing list.