Peder O. Klingenberg <email@example.com> wrote:
| firstname.lastname@example.org (Rob Warnock) writes:
| > (or (eq x y)
| > (and (characterp x) (characterp y) (char= x y))
| > (and (numberp x) (numberp y) (= x y)))
| > which isn't actually all that slow except for the leaf cases
| > of "char=" with hugely-complex Unicode and "=" with bignums.
| But it's wrong. (eql 1.0 1) is false, but your implementation would
| return t.
Yikes! Right you are! I'd forgotten all about that business of
"types" in numeric comparisons. *YUCK!*
So is this good enough?
(defun my-eql (x y)
((eq x y)
((and (characterp x) (characterp y))
(char= x y))
((and (complexp x) (complexp y))
(and (my-eql (realpart x) (realpart y))
(my-eql (imagpart x) (imagpart y))))
((and (numberp x)
(subtypep (type-of x) (type-of y))
(subtypep (type-of y) (type-of x)))
(= x y))
It does at least satisfy the weird complex number example cases
at the bottom of CLHS "Function EQL"...
Rob Warnock <email@example.com>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607