4

I really cant figure out the major difference between eq?, eqv? and equal?

Please explain this.

Besides, why do we need them?

Drew
  • 29,895
  • 7
  • 74
  • 104
  • Use eq? For symbols and to identify same object, equal? for stuff that look the same. (Land of LISP) – Sylwester Jul 09 '13 at 15:21
  • 1
    of the two answers on the duplicate, one is nothing but a link - to the whole-document PDF at that, not even to a specific section - and the other is not much more than a link either - it does mention "value equivalence" and "same object" but does not explain what these terms mean. So the question is left unanswered in the "duplicate" IMHO. Vote to reopen. – Will Ness Jul 10 '13 at 08:46
  • 1
    @WillNess The answers to this question are similar, so nothing is gained by keeping both versions. Maybe merge them and/or place a bounty on the original? – finnw Jul 14 '13 at 14:20
  • @finnw whatever you feel is right. :) I'm not good with this meta stuff. :) Merging seems right, how do we do that? – Will Ness Jul 14 '13 at 15:03

2 Answers2

4

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.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
1

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!

GoZoner
  • 67,920
  • 20
  • 95
  • 145