home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / runtime / equals.scm < prev    next >
Text File  |  1999-01-02  |  2KB  |  75 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: equals.scm,v 14.8 1999/01/02 06:11:34 cph Exp $
  4.  
  5. Copyright (c) 1988-1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. |#
  21.  
  22. ;;;; Equality
  23. ;;; package: ()
  24.  
  25. (declare (usual-integrations))
  26.  
  27. (define (eqv? x y)
  28.   ;; EQV? is officially supposed to work on booleans, characters, and
  29.   ;; numbers specially, but it turns out that EQ? does the right thing
  30.   ;; for everything but numbers, so we take advantage of that.
  31.   (or (eq? x y)
  32.       (if (object-type? (object-type x) y)
  33.       (and (not (fix:fixnum? x))
  34.            (if (number? y)
  35.            (and (= x y)
  36.             (boolean=? (exact? x) (exact? y)))
  37.            (and (object-type? (ucode-type vector) y)
  38.             (fix:zero? (vector-length x))
  39.             (fix:zero? (vector-length y)))))
  40.       (and (number? x)
  41.            (number? y)
  42.            (= x y)
  43.            (boolean=? (exact? x) (exact? y))))))
  44.  
  45. (define (equal? x y)
  46.   (or (eq? x y)
  47.       (if (object-type? (object-type x) y)
  48.       (cond ((pair? y)
  49.          (and (equal? (car x) (car y))
  50.               (equal? (cdr x) (cdr y))))
  51.         ((vector? y)
  52.          (let ((size (vector-length x)))
  53.            (and (fix:= size (vector-length y))
  54.             (let loop ((index 0))
  55.               (or (fix:= index size)
  56.                   (and (equal? (vector-ref x index)
  57.                        (vector-ref y index))
  58.                    (loop (fix:+ index 1))))))))
  59.         ((string? y)
  60.          (string=? x y))
  61.         ((number? y)
  62.          (and (= x y)
  63.               (boolean=? (exact? x) (exact? y))))
  64.         ((cell? y)
  65.          (equal? (cell-contents x) (cell-contents y)))
  66.         ((bit-string? y)
  67.          (bit-string=? x y))
  68.         ((pathname? x)
  69.          (and (pathname? y)
  70.               (pathname=? x y)))
  71.         (else false))
  72.       (and (number? x)
  73.            (number? y)
  74.            (= x y)
  75.            (boolean=? (exact? x) (exact? y))))))