I really cant figure out the major difference between eq?
, eqv?
and equal?
Please explain this.
Besides, why do we need them?
I really cant figure out the major difference between eq?
, eqv?
and equal?
Please explain this.
Besides, why do we need them?
For a technical explanation, take a look at the specification, you won't find a more detailed reference. Or simply check your interpreter's documentation, for example in Racket:
(equal? v1 v2) → boolean?
Two values are
equal?
if and only if they areeqv?
, unless otherwise specified for a particular datatype. Datatypes with further specification ofequal?
include strings, byte strings, pairs, mutable pairs, vectors, boxes, hash tables, and inspectable structures. In the last six cases, equality is recursively defined; if bothv1
andv2
contain reference cycles, they are equal when the infinite unfoldings of the values would be equal.
(eqv? v1 v2) → boolean?
Two values are
eqv?
if and only if they areeq?
, unless otherwise specified for a particular datatype. The number and character datatypes are the only ones for whicheqv?
differs fromeq?
.
(eq? v1 v2) → boolean?
eq?
returns#t
ifv1
andv2
refer to the same object,#f
otherwise. See also Object Identity and Comparisons.
There are a full two pages in the RNRS specification related to eq?, eqv?, equal? and =
. Here is the Draft R7RS Specification. Check it out!