[plt-scheme] macros: incompatible ellipsis match counts

From: Jon Rafkind (workmin at ccs.neu.edu)
Date: Mon Feb 12 20:16:04 EST 2007


Matthew Flatt wrote:
> The rules for ellipses always take a while for me to page back in...
>
> At Mon, 12 Feb 2007 14:50:58 -0800 (PST), Ryan Culpepper wrote:
>   
>>> (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.
>>     
>
> It's ok to have extra ellipses after a pattern variable in a template.
> The rule is that the innermost ellipses are treated in the usual way,
> and then the overall result is repeated as many times as necessary for
> remaining ellipses (where the repeat count for each remaining ellipses
> is determined by some other variable).
>
> Meanwhile, the count for each ellipses must be determined by at least
> one pattern variable. Incompatible-count errors are possible if the
> count is determined by more than one variable.
>
> In this case:
>
>         (begin
>           (begin z f ...) ...)
>         ...)
>
> The count for the first `...' is determined by `f', the count for the
> second `...' is determined by both `z' and `(f ...)', and the count for
> the last is determined by `(z ...)'.
>
>   
I think you lose me right about here. Why does the last ellipses depend 
on `(z ...)' and not `((z ...) f ...)' ? I thought ... matched the 
previous s-expression in its entirety.

Also it feels to me like the second set of ellipses shouldn't depend on 
both z and f. Since f is already repeated in the begin the outer ... 
should just repeat the begin for each z.




Posted on the users mailing list.