Macro expander bug causes duplicate variable errors

Issue #268 invalid
Former user created an issue

Thank you very much for the quick fix of the previous macro expander bug I reported.

Here, I have found another one while trying to port a program to Sagittarius. It seems to be more subtle.

In the program below, Sagittarius expands the line marked with "Test 1" without any complaint; on the other hand, it complains about a duplicate variable for the same expansion when it happens inside the let at the line marked with "Test 2".

The duplicate variable comes from the definition marked with "X", I think. But the way the macro works, the definition should be expanded into (define (c a b) 42) with a and b the original identifiers, so there should be no duplicate variable.

(import (scheme base)
            (scheme write))

(define-syntax aux0
  (syntax-rules ()
    ((_ z k)
     (begin
       (define-syntax z
         (syntax-rules ()
           ((_ %k) %k)))
       (z k)))))

(define-syntax aux1
  (syntax-rules ()
    ((_ x* x)
     (aux2 x* () x))))

(define-syntax aux2
  (syntax-rules ()
    ((_ () y* x)
     (define (c . y*) 42)) ; X
    ((_ (w . x*) (y* ...) x)
     (aux0 x (aux2 x* (y* ... w) x)))))

;; Test 1
(aux1 (a b) y)

(let ()
  ;; Test 2
  (aux1 (a b) y)

  'foo)

Comments (2)

  1. Marc Nieper-Wißkirchen

    I’m sorry, after a bit more experimentation I realized that the problem is with my test code and not with Sagittarius so this issue can be closed. The duplicate variable error is not due to the definition marked with “X” but due to the definition `(define-syntax z ...)` which will be inserted twice with `z` being the same `x` both times.

    Thus, this issue can be considered resolved and close. Please excuse the false alarm.

    Marc

  2. Log in to comment