[Sorry for the belated reply... still catching
up from whatever the local cold/flu crud was...]
Vassil Nikolov <vnikolov+usenet@pobox.com> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) said:
| | (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))
|
| You can use = for complex numbers as well.
+---------------
Uh... Actually, no you can't!! :-(
> (= #c(4 5) #c(4.0 5.0))
T
> (eql #c(4 5) #c(4.0 5.0))
NIL
>
Look at the bottom of the CLHS "Function EQL" page which
specifically discusses this case, and which is why I put
the test for COMPLEX before the test for NUMBER:
Two complex numbers are considered to be eql if their
real parts are eql and their imaginary parts are eql.
Compare with CLHS "Function =", which says:
Two complexes are considered equal by = if their real
and imaginary parts are equal according to =.
But EQL & "=" treat fixed & float equality differently:
> (= 4 4.0)
T
> (eql 4 4.0)
NIL
>
+---------------
| A bigger worry is the use of TYPE-OF, though---somehow,
| it lacks that proverbial warm, fuzzy feeling...
+---------------
I didn't like it either, but I couldn't think of any other way to
exactly match the semantics of the CLHS "Function EQL", which says:
2. If x and y are both numbers of the same type and the same value.
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607