[racket-dev] submodule in macro

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jan 29 08:15:25 EST 2013

There seems to be a problem with `expand' and `quote'd module names.
You can work around the problem by using `(submod "." tmp-module-name)'.

At Mon, 28 Jan 2013 03:30:21 -0500, Stephen Chang wrote:
> Actually, moving the rename to the require doesnt work either. But now
> there's a different error.
> 
> Welcome to DrRacket, version 5.3.2.2 [3m].
> Language: racket [custom].
> . . ..\..\plt\collects\racket\require-transform.rkt:266:2:
> syntax-local-module-exports: unknown module
>   module name: #<resolved-module-path:'tmp-module-name>
> >
> 
> On Sat, Jan 26, 2013 at 6:55 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> > At Sat, 26 Jan 2013 01:12:04 -0500, Stephen Chang wrote:
> >> Is this a supported use of submodules?
> >>
> >>
> >> #lang racket
> >>
> >> (define-syntax (def-wrapped stx)
> >>   (syntax-case stx ()
> >>     [(_ (f arg ...) body ...)
> >>      #'(begin
> >>          (module tmp-module-name racket
> >>            (define (f-tmp arg ...) (displayln "wrapper") body ...)
> >>            (provide (rename-out [f-tmp f])))
> >>          (require (quote tmp-module-name)))]))
> >>
> >> (def-wrapped (f x) (+ x 1))
> >> (f 100)
> >>
> >>
> >> Welcome to DrRacket, version 5.3.1.3 [3m].
> >> Language: racket [custom].
> >> . f: unbound identifier in module in: f
> >
> > Your `require' is macro-introduced, so it only binds uses that are also
> > macro-introduced. Try renaming on import, since the rename target is an
> > identifier supplied to the macro:
> >
> > #lang racket
> >
> > (define-syntax (def-wrapped stx)
> >   (syntax-case stx ()
> >     [(_ (f arg ...) body ...)
> >      #'(begin
> >          (module tmp-module-name racket
> >            (define (f-tmp arg ...) (displayln "wrapper") body ...)
> >            (provide f-tmp))
> >          (require (rename-in (quote tmp-module-name)
> >                              [f-tmp f])))]))
> >
> > (def-wrapped (f x) (+ x 1))
> > (f 100)
> >

Posted on the dev mailing list.