- edited description
Collaborating syntax-case and er macro
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)
-
reporter -
reporter Actually, this should print
ng
becauseimport
is bound and indicating different binding. The reason why it printsok
is thatcompare
procedure iner-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). -
reporter - changed status to resolved
Using usage env for ensuring identifier on er macro's compare procedure. (Fixes
#96)→ <<cset 72930f87f53e>>
-
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
-
reporter - changed status to resolved
Changing er-rename to preserve identifiers the same way as syntax-case. (Fixes
#96)→ <<cset f335dc22f9e3>>
- Log in to comment