[plt-scheme] Re: misplaced ellipses

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Feb 26 15:57:33 EST 2008

At Tue, 26 Feb 2008 15:41:35 -0500, David Van Horn wrote:
> Matthew Flatt wrote:
> > At Tue, 26 Feb 2008 13:48:45 -0500, David Van Horn wrote:
> >> (define-syntax f
> >>    (syntax-rules ()
> >>      [(f id)
> >>       (syntax (... id))]))
> >>
> >> (f ...)
> >> ;; expect (syntax (... ...)),
> >> ;; ie., the identifier `...'.
> >>
> >>
> >> I get instead:
> >>
> >> syntax: misplaced ellipses in template in: ...
> >>
> >> Why is this the case?
> > 
> > The macro `(f ...)' expands to `(syntax ...)', which is indeed a syntax
> > error.
> 
> If the syntax-rule is
> 
>    (f id) =transcribe=> (syntax (... id))
> 
> I would expect (f ...) =transcribe> (syntax (... ...)), which is not a 
> syntax error.

The quoting action of the `...' happens in the `syntax-rules' template,
though. As a template, within the `syntax-rules' form,

 (syntax (... id))

is the same as

 (syntax id)

because the `...' quotes `id' (which doesn't actually need it).

Since you want two levels of `syntax' quoting, you need two levels of
`...' quoting within the `syntax-rules' form:

  (syntax ((... ...) id))
            ^^^ ^^^------- quotes `id' in the expansion
             `-------quotes the `...' that comes next

or, equivalently and maybe easier to read:

  (... (syntax (... id)))
   ^^^          ^^^------- quotes `id' in the expansion
     `-------quotes the `...' later


Matthew



Posted on the users mailing list.