manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1.2 Equivalence predicates

procedure: eqv? obj1 obj2
procedure: eq? obj1 obj2

eqv? and eq? are equivalent in Bigloo.

(eq? 'a 'a)                            ⇒  #t
(eq? '(a) '(a))                        ⇒  unspecified
(eq? (list 'a) (list 'a))              ⇒  #f
(eq? "a" "a")                          ⇒  unspecified
(eq? "" "")                            ⇒  unspecified
(eq? '() '())                          ⇒  #t
(eq? 2 2)                              ⇒  unspecified
(eq? #\A #\A)                          ⇒  unspecified
(eq? car car)                          ⇒  #t
(let ((n (+ 2 3)))
  (eq? n n))                           ⇒  unspecified
(let ((x '(a)))
  (eq? x x))                           ⇒  #t
(let ((x '#()))
  (eq? x x))                           ⇒  #t
(let ((p (lambda (x) x)))
  (eq? p p))                           ⇒  #t

Since Bigloo implements eqv? as eq?, the behavior is not always conforming to R5RS.

(eqv? 'a 'a)                           ⇒  #t
(eqv? 'a 'b)                           ⇒  #f
(eqv? 2 2)                             ⇒  #t
(eqv? '() '())                         ⇒  #t
(eqv? 100000000 100000000)             ⇒  #t
(eqv? (cons 1 2) (cons 1 2))           ⇒  #f
(eqv? (lambda () 1)
      (lambda () 2))                   ⇒  #f
(eqv? #f 'nil)                         ⇒  #f
(let ((p (lambda (x) x)))
  (eqv? p p))                          ⇒  unspecified

The following examples illustrate cases in which the above rules do not fully specify the behavior of ‘eqv?’. All that can be said about such cases is that the value returned by ‘eqv?’ must be a boolean.

(eqv? "" "")                           ⇒  unspecified
(eqv? '#() '#())                       ⇒  unspecified
(eqv? (lambda (x) x)
      (lambda (x) x))                  ⇒  unspecified
(eqv? (lambda (x) x)
      (lambda (y) y))                  ⇒  unspecified

(define gen-counter
  (lambda ()
    (let ((n 0))
      (lambda () (set! n (+ n 1)) n))))
(let ((g (gen-counter)))
  (eqv? g g))                          ⇒  #t
(eqv? (gen-counter) (gen-counter))
                                       ⇒  #f
(define gen-loser
  (lambda ()
    (let ((n 0))
      (lambda () (set! n (+ n 1)) 27))))
(let ((g (gen-loser)))
  (eqv? g g))                          ⇒  #t
(eqv? (gen-loser) (gen-loser))
                                       ⇒  unspecified

(letrec ((f (lambda () (if (eqv? f g) 'both 'f)))
         (g (lambda () (if (eqv? f g) 'both 'g))))
  (eqv? f g))
                                       ⇒  unspecified

(letrec ((f (lambda () (if (eqv? f g) 'f 'both)))
         (g (lambda () (if (eqv? f g) 'g 'both))))
  (eqv? f g))
                                       ⇒  #f
(eqv? '(a) '(a))                       ⇒  unspecified
(eqv? "a" "a")                         ⇒  unspecified
(eqv? '(b) (cdr '(a b)))               ⇒  unspecified
(let ((x '(a)))
  (eqv? x x))                          ⇒  #t
library procedure: equal? obj1 obj2
(equal? 'a 'a)                         ⇒  #t
(equal? '(a) '(a))                     ⇒  #t
(equal? '(a (b) c)
        '(a (b) c))                    ⇒  #t
(equal? "abc" "abc")                   ⇒  #t
(equal? 2 2)                           ⇒  #t
(equal? (make-vector 5 'a)
        (make-vector 5 'a))            ⇒  #t
(equal? (lambda (x) x)
        (lambda (y) y))                ⇒  unspecified

See (R5RS)r5rs.info, for more details.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on March 31, 2014 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.