[plt-scheme] re: another macro+module anomaly
Several months ago I posted a query regarding matching literals in macros,
for which the answer was to use syntax-case* with
'module-or-top-identifier=?'. For my problem at the time, this solved the
problem.
But a curious point for me, was that I had a problem symbols which were, also
bound MzScheme _values_. 'or' and 'and' seemed to work just fine. I think,
mistakenly, I concluded that this was a problem for value bindings, but not
syntactic bindings. I say this because, while 'or' and 'and' work just fine,
with-or-without the use of 'module-or-top-identifier=?', "class" fails even
with the use of 'module-or-top-identifier=?'. Now I am just confused ;)
The module:
(module ex mzscheme
(provide test)
(require-for-syntax (lib "stx.ss" "syntax"))
(define-syntax (test stx)
(syntax-case* stx (- or class) module-or-top-identifier=?
((_ (- a b))
(syntax '(subtract a b)))
((_ (class a b))
(syntax '(matched a b)))
((_ (or a b))
(syntax '(intersection a b)))
((_ (op a b))
(syntax '(op a b)))))
)
This follows the early proposed solution, and hence,
(test (or 1 5)) ==> (intersection 1 5)
And, of course, the original "problem"
(test (- 1 5))
produces "(subtract 1 5)" as intended.
But curiously,
(test '(class 1 5))
produces "(class 1 5)"
rather than the (intended--for this silly test) "(matched 1 5)".
As a work around, I am simply coercing the syntax object into a datum, and
testing whether this eq?'s 'class. But is there a better way to deal with
this?
I have tested this with both v202 and v203, with the same results.
Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20030406/c0b3de92/attachment.html>