(Scheme) eq? eqv? equal? Difference
equality, lisp, scheme
Solution
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 are `eqv?`, unless otherwise specified for a particular datatype. Datatypes with further specification of `equal?` include strings, byte strings, pairs, mutable pairs, vectors, boxes, hash tables, and inspectable structures. In the last six cases, equality is recursively defined; if both `v1` and `v2` 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 are `eq?`, unless otherwise specified for a particular datatype. The number and character datatypes are the only ones for which `eqv?` differs from `eq?`.
`(eq? v1 v2) → boolean?`
`eq?` returns `#t` if `v1` and `v2` refer to the same object, `#f` otherwise. See also Object Identity and Comparisons.
Problem
I really cant figure out the major difference between `eq?`, `eqv?` and `equal?` Please explain this. Besides, why do we need them?