[plt-scheme] another macro+module anomaly
At Tue, 26 Nov 2002 23:06:45 EST, Benderjg2 at aol.com wrote:
> (module ex mzscheme
> (provide test)
>
> (define-syntax (test stx)
> (syntax-case stx (-)
> ((_ (- a b))
> (syntax '(subtract a b)))
> ((_ (op a b))
> (syntax '(op a b)))))
> )
>
> When I test this macro (at the top level),
> (test (+ 3 4)) ==> (+ 3 4) ;; this is "correct"
> and
> (test (- 3 4)) ==> (- 3 4) ;; this is wrong!
This is an annoying problem with the top level that I don't know how to
avoid while still conforming to R5RS.
One solution is to `(require mzscheme)' in the top level, if you have
control over it.
The more general solution is to use `module-or-top-identifier=?' for
comparing literals:
(module ex mzscheme
(provide test)
(require-for-syntax (lib "stx.ss" "syntax"))
(define-syntax (test stx)
(syntax-case* stx (-) module-or-top-identifier=?
((_ (- a b))
(syntax '(subtract a b)))
((_ (op a b))
(syntax '(op a b)))))
)
Matthew