[plt-scheme] an issue with macros expanding to transformers

From: Michele Simionato (michele.simionato at gmail.com)
Date: Sun Mar 1 00:39:22 EST 2009

While porting some macros from Ikarus to PLT Scheme I found out an
issue
that baffles me.
Here is the simplified version of the problem. I want to define a
second
order macro, i.e. a macro which expands to a macro transformer.
So I put in a helper module the following make-transformer macro:

#!r6rs
(library (helper)
(define-syntax make-transformer
  (syntax-rules ()
    ((_ (name value) ...) (syntax-rules (<names> name ...)
                            ((_ <names>) '(name ...))
                            ((_ name) value) ...))))
)

Then I tried to use it in a script as follows:

#!r6rs
(import (rnrs) (for (helper) expand))

(define-syntax m (make-transformer (x 1) (y 2)))
(display (m x))
(display (m y))
(display (m <names>))

In theory the macro m should be equivalent to

(define-syntax m (syntax-rules (<names> x y)
                            ((_ <names>) '(x y))
                            ((_ x) 1)
                            ((_ y) 2)))

and actually (m x) returns 1 and (m y) returns 2 as expected.
However, (m <names>) does not return '(x y) as it should;
instead I get an error:

 compile: bad syntax; function application is not allowed, because no #
%app syntax transformer is bound in: (quote (x y))

(tested in PLT 4.0). How am I supposed to solve this?
TIA,

                           Michele Simionato


Posted on the users mailing list.