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

_______________________________________________
Chicken-hackers mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to