[plt-scheme] match patterns for eq?/eqv?/equal? bound values
Hi all,
I am currently using MzScheme 4.2.1
I have been using pattern matching and feel like there is something
missing (or that I am failing to see). In particular, I am surprised
there are no built-in patterns for matching values that are
eq?/eqv?/equal? to an expected value bound to a variable. The ? pattern
can obviously be used:
(match v
((? (lambda (arg) (eq? arg expected)))
'match))
but I was thinking there would be something less verbose, like:
(match v
((eq expected)
'match))
I defined my own expander(s) to accomplish this, like for eq?:
(define-match-expander eq
(syntax-rules ()
((eq x1)
(? (lambda (x2) (eq? x1 x2))))))
Obviously for my simple example above a match form is not really needed,
but when nesting patterns this eq pattern becomes quite helpful in
maintaining readability:
(match lst
((list (eq foo) (eq bar) rest)
rest))
Anyway, I'm wondering if I'm missing an existing facility for doing this
or whether I should simply continue to use my own expanders.
Thanks.
David