A possible macro (let-syntax) bug

Issue #110 resolved
Former user created an issue

I've made a test case to show a strange warning message I got. The code works in chicken and larceny scheme but not sagittarius.

x.sld:

(define-library (x)
  (import (scheme base) (scheme write))
  (export example-1 example-2)
  (begin

    (define-syntax begin-scope
      (syntax-rules ()
    ((begin-scope defer <body> ...)
     (let ((stuff '()))
       (let-syntax ((defer (syntax-rules ()
                 ((defer <statement>)
                  (set! stuff (cons <statement> stuff))
                  ))))
         (begin <body> ...))
       (for-each display stuff)))))

    (define (example-1)
      (begin-scope defer
           (display "one")
           (display "two")
           (display "three")))

    (define (example-2)
      (begin-scope defer
           (display "one")
           (defer (display "two"))
           (display "three")))))

Then loading it:

$ rlwrap sagittarius -c -L. -S.sld
sash> (import (x))
WARNING: reference to undefined variable: 'stuff' in (x)
WARNING: reference to undefined variable: 'stuff' in (x)
#<unspecified>
sash> (example-1)
onetwothree#<unspecified>
sash> (example-2)
onetwo*error*

It looks like the let-syntax was not able to capture the variable "stuff" to make use of.

I hope this report is useful!

Comments (1)

  1. Takashi Kato repo owner

    Thanks for the report!

    Confirmed on 0.6.2 and has been fixed on 0.6.3. This is the same issue as #103.

    The reason why is that the R7RS let-syntax is implemented with R6RS syntax-rules however on 0.6.2 mixing R6RS and R7RS macro doesn't work on certain case (this is one of them). This is basically related to renaming bug on er-macro-transformer.

    I've added the test case for this: 144d01a

  2. Log in to comment