eqv? -- r7rs Definition comparator;
equivalent-by-value-strict? (from vonuvoli);Procedure variants:
((any any) -> (boolean))
scheme:base -- (scheme base);scheme -- (scheme);(eqv? obj_1 obj_2)The
eqv?procedure defines a useful equivalence relation on objects. Briefly, it returns#tifobj_1andobj_2are normally regarded as the same object. This relation is left slightly open to interpretation, but the following partial specification ofeqv?holds for all implementations of Scheme.The
eqv?procedure returns#tif:
obj_1andobj_2are both#tor both#f.
obj_1andobj_2are both symbols and are the same symbol according to thesymbol=?procedure.
obj_1andobj_2are both exact numbers and are numerically equal (in the sense of=).
obj_1andobj_2are both inexact numbers such that they are numerically equal (in the sense of=) and they yield the same results (in the sense ofeqv?) when passed as arguments to any other procedure that can be defined as a finite composition of Scheme's standard arithmetic procedures, provided it does not result in aNaNvalue.
obj_1andobj_2are both characters and are the same character according to thechar=?procedure.
obj_1andobj_2are both the empty list.
obj_1andobj_2are pairs, vectors, bytevectors, records, or strings that denote the same location in the store.
obj_1andobj_2are procedures whose location tags are equal.The
eqv?procedure returns#fif:
obj_1andobj_2are of different types.one of
obj_1andobj_2is#tbut the other is#f.
obj_1andobj_2are symbols but are not the same symbol according to thesymbol=?procedure.one of
obj_1andobj_2is an exact number but the other is an inexact number.
obj_1andobj_2are both exact numbers and are numerically unequal (in the sense of=).
obj_1andobj_2are both inexact numbers such that either they are numerically unequal (in the sense of=), or they do not yield the same results (in the sense ofeqv?) when passed as arguments to any other procedure that can be defined as a finite composition of Scheme's standard arithmetic procedures, provided it does not result in aNaNvalue. As an exception, the behavior ofeqv?is unspecified when bothobj_1andobj_2areNaN.
obj_1andobj_2are characters for which thechar=?procedure returns#f.one of
obj_1andobj_2is the empty list but the other is not.
obj_1andobj_2are pairs, vectors, bytevectors, records, or strings that denote distinct locations.
obj_1andobj_2are procedures that would behave differently (return different values or have different side effects) for some arguments.(eqv? 'a 'a) ===> #t (eqv? 'a 'b) ===> #f (eqv? 2 2) ===> #t (eqv? 2 2.0) ===> #f (eqv? '() '()) ===> #t (eqv? 100000000 100000000) ===> #t (eqv? 0.0 +nan.0) ===> #f (eqv? (cons 1 2) (cons 1 2)) ===> #f (eqv? (lambda () 1) (lambda () 2)) ===> #f (let ((p (lambda (x) x))) (eqv? p p)) ===> #t (eqv? #f 'nil) ===> #fThe 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 byeqv?must be a boolean.(eqv? "" "") ===> #unspecified (eqv? '#() '#()) ===> #unspecified (eqv? (lambda (x) x) (lambda (x) x)) ===> #unspecified (eqv? (lambda (x) x) (lambda (y) y)) ===> #unspecified (eqv? 1.0e0 1.0f0) ===> #unspecified (eqv? +nan.0 +nan.0) ===> #unspecifiedNote that
(eqv? 0.0 -0.0)will return#fif negative zero is distinguished, and#tif negative zero is not distinguished.Since it is an error to modify constant objects (those returned by literal expressions), implementations may share structure between constants where appropriate. Thus the value of
eqv?on constants is sometimes implementation-dependent.(eqv? '(a) '(a)) ===> #unspecified (eqv? "a" "a") ===> #unspecified (eqv? '(b) (cdr '(a b))) ===> #unspecified (let ((x '(a))) (eqv? x x)) ===> #tThe above definition of
eqv?allows implementations latitude in their treatment of procedures and literals: implementations may either detect or fail to detect that two procedures or two literals are equivalent to each other, and can decide whether or not to merge representations of equivalent objects by using the same pointer or bit pattern to represent both.Note: If inexact numbers are represented as IEEE binary floating-point numbers, then an implementation of
eqv?that simply compares equal-sized inexact numbers for bitwise equality is correct by the above definition.
The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.