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

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Mon Mar 2 10:39:20 EST 2009

The following works on my computer:


#!r6rs
(library (helper)
        
         (export make-transformer)
         (import (rnrs) (for (rnrs) (meta -1)))
        
         (define-syntax make-transformer
           (syntax-rules ()
             ((_ (name value) ...)
              (syntax-rules (<names> name ...)
                ((_ <names>) '(name ...))
                ((_ name) value) ...))))
         )

Chongkai

Michele Simionato wrote:
> 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
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>   



Posted on the users mailing list.