[plt-scheme] Custom match expanders for eq?, eqv? and equal?

From: Dave Gurnell (d.j.gurnell at gmail.com)
Date: Tue Aug 19 13:00:12 EDT 2008

Hi PLTers,

I've often thought an equivalent of "eq?" or "equal?" to be a useful  
addition for the match library. "?" does more or less what I want but  
it's a little verbose:

   (define x 'a)
   (define y 'b)

   (match x
     [(? (cut eq? <> y)) "X is the same as Y."])

What I'd like to see is something like this:

   (match x
     [(eq? y) "X is the same as Y."])

I had a play this afternoon and wrote the a module called "my- 
match.ss" (attached) that redefines eq?, eqv? and equal? to do what  
I've described above:

   #lang scheme

   (require (file "my-match.ss"))

   ; and so on...

Now for my question. By supplying my own versions of these  
identifiers, I have also changed how they are treated in an expression  
context (although the end result of using them should be the same). Is  
it a "Bad Thing" (TM) to do this to identifiers that are so  
fundamental to the core of Scheme? Should I rename these guys, or make  
sure I only ever require them with a prefix?

Many thanks,

-- Dave

; my-match.ss ====================================

#lang scheme

(require srfi/26)

; Match expanders --------------------------------

; (_ expr pattern ...)
(define-match-expander match:eq?
   (syntax-rules ()
     [(_ value pattern ...)
      (? (cut eq? <> value) pattern ...)])

; (_ expr pattern ...)
(define-match-expander match:eqv?
   (syntax-rules ()
     [(_ value pattern ...)
      (? (cut eqv? <> value) pattern ...)])

; (_ expr pattern ...)
(define-match-expander match:equal?
   (syntax-rules ()
     [(_ value pattern ...)
      (? (cut equal? <> value) pattern ...)])

; Provide statements -----------------------------

(provide (rename-out [match:eq?    eq?]
                      [match:eqv?   eqv?]
                      [match:equal? equal?]))

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080819/d02835ee/attachment.html>

Posted on the users mailing list.