[plt-scheme] Macro ellipsis question

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Jan 27 10:22:24 EST 2009

On Jan 27, James Coglan wrote:
> > > (define-syntax parallel-set!
> > >   (syntax-rules ()
> > >     [(parallel-set! (symbol ...) (value ...))
> > >       (set! symbol value) ...]))

Just a quick note here: especially if you want to implement your own
macro expanded -- using "symbol" as a name for identifiers is a bad
idea.  It doesn't make the code incorrect, of course, but it indicates
some other confusion.  (Basically, hygiene means that identifiers are
not just symbols.)

> > > (parallel-set! (a b c) (1 2 3))
> > > ; a = 1, b = 2, c = 3
> >
> > Only one form is allowed in the template portion of `syntax-rules',
> > but you have two: (set! symbol value) and ... .
> >
> > You probably want
> >
> > (begin (set! symbol value) ...)
> Could someone second this? I thought I saw multi-statement templates
> in some examples though I can't remember where. R5RS would seem to
> agree with Sam but I'd like to be sure.

Thirded.  You're getting to an obscure point in the language: `begin'
is actually overloaded, and it's doing two things -- it is used to
sequence expressions when side effects are involved, and it's also
used in macro results to "splice" them into the context that used the
macro.  This is something that people don't usually notice, but in
some cases it can be very confusing, and when you're dealing with
syntax you must know about it in many contexts where you need to
"flatten" the `begin's in some syntax.  Another example where a
differece is visible is in Lazy Scheme: `begin' could be just a
function for the first role, but it must be a syntax to get the second
one too.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.