[plt-scheme] macros: incompatible ellipsis match counts

From: Robby Findler (robby at cs.uchicago.edu)
Date: Mon Feb 12 17:58:24 EST 2007

On 2/12/07, Ryan Culpepper <ryan_sml at yahoo.com> wrote:
>
> --- Jon Rafkind <workmin at ccs.neu.edu> wrote:
>
> > I was playing around with macros and am having trouble
> > understanding
> > whats going wrong here. This macro works
> >
> > (define-syntax foo2
> >   (syntax-rules ()
> >     ((_ (z ...) f ...)
> >      (begin
> >        (begin z f ...) ...))))
> >
> > (foo2 (1 2 3) 4 5 6)
> >
> > The macro stepper says it evaluates to
> > (begin (begin 1 4 5 6) (begin 2 4 5 6) (begin 3 4 5 6))
> >
> > But if I put another ... after (z ...) f ... then things break.
> >
> > (define-syntax foo3
> >   (syntax-rules ()
> >     ((_ ((z ...) f ...) ...)
> >      (begin
> >        (begin
> >          (begin z f ...) ...)
> >        ...)
> >        )))
>
> This 'syntax-rules' expression is wrong. The 'z' pattern variable has
> an ellipsis-depth of 2, and the 'f' pattern variable also has an
> ellipsis-depth of 2. In the template, though, you're using 'f' at a
> depth of 3. Usually that kind of error is caught at compile time. You
> seem to have found a bug in mzscheme's syntax-rules/syntax-case.

But why did the first one work? It seems that, under that logic, both
z and f were at ellipsis depth 1 in the first example, but f is being
used at depth 2 in the right-hand side.

In general, the two pattern/uses seem the same except one has an extra
pair of ellipsis around it. Consistently adding another level of
nesting shouldn't break anything, should it?

In the first one, I see that the 4 5 6 is duplicated once for each of
the 1 2 3. Could that not also happen at higher levels of ellipses?

Robby


Posted on the users mailing list.