chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Expanding ellipsis on lists of different length


From: Tobia Conforto
Subject: Re: [Chicken-users] Expanding ellipsis on lists of different length
Date: Wed, 27 Aug 2008 21:55:26 +0200

Elf wrote:
Tobia Conforto wrote:
(define-syntax test
  (syntax-rules ()
    ((test (a ...) (b ...))
     (quote ((a b) ...)))))


i believe that this is an error in chicken. there are two ellipses in the pattern and only one in the output spec, so in both cases it should error with an invalid transformer spec notice.

I beg to differ. This is a perfectly valid syntax-rule. The number of ellipses in the pattern doesn't need to match those in the template, not in this way. For example this is valid too--it does the opposite of test:

(define-syntax untest
  (syntax-rules ()
    ((untest (a b) ...)
     (quote ((a ...) (b ...))))))

(untest (1 10) (2 20) (3 30))  =>  ((1 2 3) (10 20 30))


additionally, the 'a' isnt followed by an ellipsis, nor is the 'b' followed by an ellipsis, which is specifically the error referred to here: 'pattern variables that occur in subpatterns followed by one or more instances of the identifier ... are allowed only in subtemplates that are followed by as many instances of ... . they are replaced in the output by all of the subforms they match in the input, distributed as indicated.

I think you are reading it wrong.  Let's apply it to "test":

(define-syntax test
  (syntax-rules ()
    ((test (a ...) (b ...))
     (quote ((a b) ...)))))

Pattern variables [for example, the 'b inside (b ...)] that occur in subpatterns [the same 'b is also the subpattern in this case] followed by one or more instances of the identifier "..." [one instance] are allowed *only* in subtemplates [(a b) is the subtemplate] that are followed by as many instances of "..." [again one instance.]

Applied to "untest":

(define-syntax untest
  (syntax-rules ()
    ((untest (a b) ...)
     (quote ((a ...) (b ...))))))

Pattern variables [for example, the 'a in (a b)] that occur in subpatterns [(a b) is the subpattern] followed by one or more instances of the identifier "..." [one instance] are allowed *only* in subtemplates [the 'a inside (a ...) is the subtemplate] that are followed by as many instances of "..." [again one instance.]


AFAICS, the only possible error that can happen at macro expansion time, related to the ellipsis, is to take a macro combining several pattern-ellipses into one template-ellipsis (such as "test" above) and apply it to lists of different length. What I'm proposing is to always signal it as an error, not just half of the times.


Tobia




reply via email to

[Prev in Thread] Current Thread [Next in Thread]