[plt-scheme] Splicing macro containing ...

From: Noel Welsh (noelwelsh at gmail.com)
Date: Thu Apr 30 09:47:32 EDT 2009

Hello all,

Another macro question. I'm trying to splice a macro containing
ellipses into an expression context, and I'm getting the error

  syntax: no pattern variables before ellipses in template in: ...

Only an ellipsis causes an error; other macros and normal expressions
work fine. My setup is a little convoluted -- I'm defining a macro
that defines a macro. Both macros specify imports and exports. The
names specified in the top macro are names used in the body. The names
specified in the internal macro specify actual imports and exports. So
this system is something like a unit, where the internal names may
differ to the actual names the abstraction is linked against and
exports. Code illustrating the problem is below; hopefully this will
be clearer than my explanation.

Thanks for all help,

#lang scheme/base

 (for-syntax scheme/base

(define-syntax (define-foo stx)
  (syntax-case stx (import export)
    [(define-foo name
       (import import-id)
       (export export-id)
       body-expr ...)
     #`(define-syntax (name stx)
         (syntax-case stx (import export)
             (import real-import-id)
             (export real-export-id))
                (define import-id real-import-id)
                  body-expr ...)
                (define real-export-id export-id))]))]))

(define-foo bar
  (import baz)
  (export number)
  (define number
    (baz 1 2 3)))

 (import +)
 (export magic-number))


(define-foo broken
  (import baz)
  (export number)
  (define-syntax quux
    (syntax-rules ()
      [(quux a b c ...)
       (baz a b c ...)]))
  (define number
    (quux 1 2 3)))

 (import +)
 (export broken-number))


Posted on the users mailing list.