Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Scheme) eq? eqv? equal? Difference [duplicate]

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

Please explain this.

Besides, why do we need them?

like image 805
Agnishom Chattopadhyay Avatar asked Oct 24 '25 02:10

Agnishom Chattopadhyay


1 Answers

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.

like image 128
Óscar López Avatar answered Oct 27 '25 00:10

Óscar López