Next: Object Properties, Up: Utility Functions
Three different kinds of sameness are defined in Scheme.
The differentiation between these three kinds is important, because determining whether two values are the same objects is very efficient, while determining structural equivalence can be quite expensive (consider comparing two very long lists). Therefore, three different procedures for testing for equality are provided, which correspond to the three kinds of sameness defined above.
Return
#tiff x references the same object as y.eq?is similar toeqv?except that in some cases it is capable of discerning distinctions finer than those detectable byeqv?.
The
eqv?procedure defines a useful equivalence relation on objects. Briefly, it returns#tif x and y should normally be regarded as the same object. This relation is left slightly open to interpretation, but works for comparing immediate integers, characters, and inexact numbers.
Return
#tiff x and y are recursivelyeqv?equivalent.equal?recursively compares the contents of pairs, vectors, and strings, applyingeqv?on other objects such as numbers and symbols. A rule of thumb is that objects are generallyequal?if they print the same.equal?may fail to terminate if its arguments are circular data structures.