[R6RS] Internal DEFINE vs. macros

dyb at cs.indiana.edu dyb
Fri Apr 15 10:55:36 EDT 2005


> > (let-syntax ((foo (syntax-rules ()
> > 		    ((foo ?x) (define ?x 'outer)))))
> >   (let ()
> >     (define-syntax foo
> >       (syntax-rules ()
> > 	((foo) (define ?x 'inner))))
> >     (foo a)
> >     a))
> >
> >> produces outer on PLT, but on Chez says:
> >>
> >> Error: invalid syntax (foo a).
> >>
> >> Why?  (If you think I should wait until the full description of
> >> SYNTAX-CASE is out let me know.)
> >
> > Chez Scheme processes body forms from left to right and adds macro
> > definitions to the compile-time environment as it proceeds. [...]
>
> I'm probably being dense---why doesn't the definition of FOO get
> applied to the use then?  Why is this an error?

Yes, you are being dense ;-).  The inner foo's pattern matches (foo),
i.e., zero subforms, and the macro call is (foo a), with one subform.

You probably meant:

(let-syntax ((foo (syntax-rules ()
                ((foo ?x) (define ?x 'outer)))))
  (let ()
    (define-syntax foo
      (syntax-rules ()
    ((foo ?x) (define ?x 'inner))))
    (foo a)
    a))

Kent


More information about the R6RS mailing list