[plt-scheme] chaining module begin

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Oct 6 16:04:27 EDT 2004

This is a problem expanding to a non-hygienic macro. The
`#%module-begin' from MzScheme introduces
  (require-for-syntax mzscheme)
into the module body. It does that using the context of the
`#%module-begin' form.

In this case, you can solve the problem by putting the context of `stx'
onto the result:

 (module foo mzscheme
   (provide (all-from-except mzscheme #%module-begin)
            (rename module-begin #%module-begin))
   (define-syntax (module-begin stx)
     (syntax-case stx ()
       [(_ expr ...)
        (let ([s #'(#%module-begin
                    (write 1)
                    expr ...)])
          (datum->syntax-object stx (syntax-e s) stx))])))

Matthew

At Wed, 6 Oct 2004 15:56:13 -0400, "Mike T. Machenry" wrote:
> I am having trouble figuring out why the following does not work. I want to 
> create a module language that provided its own #%module-begin interms of 
> another module language that does that same. However, I get an error that 
> #%app is unhappy:
> 
> module-begin-problem.ss:15:4: compile: bad syntax; function application is 
> not allowed, because no #%app syntax transformer is bound in: (syntax-case 
> stx () ((_ expr ...) (syntax (#%module-begin (write 2) expr ...))))
> 
> -mike
> 
> ;;;;;;;;;;
> ;; Start Code
> 
> (module foo mzscheme
>   (provide (all-from-except mzscheme #%module-begin)
> 	   (rename module-begin #%module-begin))
>   (define-syntax (module-begin stx)
>     (syntax-case stx ()
>       [(_ expr ...)
>        #'(#%module-begin
> 	  (write 1)
> 	  expr ...)])))
> 
> (module bar foo
>   (provide (all-from-except mzscheme #%module-begin)
> 	   (rename module-begin #%module-begin))
>   (define-syntax (module-begin stx)
>     (syntax-case stx ()
>       [(_ expr ...)
>        #'(#%module-begin
> 	  (write 2)
> 	  expr ...)])))


Posted on the users mailing list.