[racket] can racket have a regexp-equal?

From: ozzloy (ozzloy at gmail.com)
Date: Fri Nov 25 16:22:30 EST 2011

i was writing a unit test which had something analogous to the following:

(check-equal? #rx"a" #rx"a")  => raises exn:test:check

so i checked and sure enough:

(equal? #rx"a" #rx"a) => #f

which led me to look for a regexp-equal? so i could do (check regexp-equal?
#rx"a" #rx"a")
that doesn't exist, so i wrote one:
(define (regexp-equal? a b)
  (and (and (regexp? a)
            (regexp? b))
       (or (and (pregexp? a)
                (pregexp? b))
           (and (not (pregexp? a))
                (not (pregexp? b))))
       (equal? (object-name a)
               (object-name b))))

why not just have (equal? #rx"a" #rx"a") => #t ?
anticipated objection: "what should equal? mean for two regexps?"
it should mean that the patterns are identical, totally ignoring that two
non-identical patterns might match exactly the same set, like #rx"(a|b)"
and #rx"(b|a)".
i see in the docs that there is an internal regexp value.  if those are
what i think they are, i propose equal? just compares those for regexes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111125/35d5ad42/attachment.html>

Posted on the users mailing list.