[plt-scheme] (module) expanded from a macro

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun Oct 22 14:07:07 EDT 2006

Dan Muresan skrev:
> Hi, I'm wondering why the following doesn't work:
> 
> (define-syntax xmodule
>    (syntax-rules ()
>      ((_ name (export ...) def ...)
>       (module name mzscheme (provide export ...)
>         def ...))))
> 
>  (xmodule mod (mac) (define-syntax mac (syntax-rules () ((_ x) x))))
> 
> I get:
> 
> compile: bad syntax; function application is not allowed, because no
> #%app syntax transformer is bound in: (syntax-rules () ((_ x) x))
> 
> However, plain definitions work inside xmodule.

Try one of these:

(define-syntax (xmodule stx)
   (syntax-case stx ()
     [(_ name (export ...) def ...)
      (syntax-local-introduce
       #'(module name mzscheme (provide export ...)
           def ...))]))

   (define-syntax (xmodule stx)
     (syntax-case stx ()
       [(_ name (export ...) def ...)
        (datum->syntax-object
         stx (syntax-object->datum
              #'(module name mzscheme (provide export ...)
                  def ...)))]))

-- 
Jens Axel Søgaard



Posted on the users mailing list.