Expanding ellipsis template raises an error if variables contains the same pattern variable

Issue #172 resolved
Takashi Kato repo owner created an issue

This raises an error:

(import (rnrs))

(define-syntax foo
  (lambda (x)
    (define (derive-it k s)
      (let loop ((r '()) (s s))
        (syntax-case s ()
          (() (datum->syntax k r))
          (((f a b) rest ...)
           (loop (cons #'(f a b) (cons #'(f a b) r)) #'(rest ...))))))
    (syntax-case x ()
      ((k (foo . bar) ...)
       (with-syntax ((((foo a b) ...)
                      (derive-it #'k #'((foo . bar) ...))))
         #''((foo a b)  ...))))))

(foo (f a b)) ;; -> shoulr return ((foo a b) (foo a b))

The root cause is that foo is bound in 2 places without renaming (so #t in sense of bound-identifier=?) and when expanding ellipsis the macro transformer collects both foo variables and thinks one of the foo doesn't have enough input.

In this case the first foo ... has only (f) however the second (newly created foo) has (f f).

There might be 2 ways to resolve this:

  1. Rename the second foo (cleaner but more difficult to handle)
  2. Ignore the first one foo when collecting the input form (dirty hack)

Comments (1)

  1. Log in to comment