chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

## [Chicken-hackers] something equal? to EQUALP

 From: Felix Subject: [Chicken-hackers] something equal? to EQUALP Date: Tue, 07 Sep 2010 09:16:13 +0200 (CEST)

```Hi!

Repeatedly I need an equivalence predicate that performs structural
comparison but also compares numbers numerically (as `=' does, note
that `equal?' does not use `=' for number comparison). Common Lisp in
all its archaic cruftiness at least provides EQUALP which does basically
the right thing (but is case-insensitive).

Here my attempt:

; an actual implementation would be more efficient and would compare
; structured data by lower-level means:

(define (equal?? x y)
(let walk ((x x) (y y))
(cond ((eq? x y))
((pair? x)
(and (pair? y)
(walk (car x) (car y))
(walk (cdr x) (cdr y))))
((vector? x)
(and (vector? y)
(walk (vector->list x) (vector->list y))))
((string? x)
(and (string? y)
(string=? x y)))
((number? x)
(and (number? y)
(= x y)))
(else #f))))

Any ideas for a better name? Any considerations that
should be taken into account?

cheers,
felix

```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]