Subject: Re: cons to the same object
From: (Rob Warnock)
Date: Fri, 16 Mar 2007 04:57:27 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Peder O. Klingenberg <> wrote:
| (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)
	      (numberp y)
	      (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			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607