Peder O. Klingenberg <peder@news.klingenberg.no> wrote:
+---------------
| rpw3@rpw3.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)
(cond
((eq x y)
t)
((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)
(numberp y)
(subtypep (type-of x) (type-of y))
(subtypep (type-of y) (type-of x)))
(= x y))
(t
nil))
It does at least satisfy the weird complex number example cases
at the bottom of CLHS "Function EQL"...
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607