Collaborating syntax-case and er macro

Create issue
Issue #96 resolved
Takashi Kato repo owner created an issue

R7RS syntax-rules is implemented on top of er macro however some cases it doesn't collaborate with syntax-case. Following code should print ok but ng.

(define-library (lib)
  (export foo)
  (import (scheme base))
  (begin
    (define-syntax import (syntax-rules ()))
    (define-syntax foo
      (syntax-rules (import)
    ((_ import) 'ok)
    ((_ _) 'ng))))
  )

(import (rnrs) (lib))

(define-syntax print
  (syntax-rules ()
    ((_ o) (begin (display o) (newline)))))

(print (foo import))

This is because when first rename is done by syntax-case then the given import is renamed to be a global variable, however comparison between literal and the identifier is not correct (ensuring identifier uses current env so it won't be the same in sense of free-identifier=?).

Comments (5)

  1. Takashi Kato reporter

    Actually, this should print ng because import is bound and indicating different binding. The reason why it prints ok is that compare procedure in er-macro-transformer uses macro env instead of usage env so ensured identifier will be macro env identifier (this must be usage env identifier since input is in usage env).

  2. Takashi Kato reporter
    • changed status to open

    This case still doesn't work

    (import (rnrs) (scheme base))
    
    (define-syntax print
      (lambda (x)
        (syntax-case x ()
          ((_ o) #'(begin (display o) (newline))))))
    
    (let ()
      (define-syntax bar
        (syntax-rules ()
          ((_ m body)
           (let ((m 1))
             (body)))))
    
      (define-syntax foo
        (syntax-rules ()
          ((_ m body)
           (let ((n 2))
             (let-syntax ((%body
                           (syntax-rules ()
                             ((_) body))))
               (bar m %body))))))
    
      (let ((n 3))
        (print (foo n (values n)))))
    

    Should print 3 but 1

  3. Log in to comment