Equality

How much are two values “the same”?

eq? is the most ruthless. The two values must reference the same memory or be otherwise indistinguishable in memory.

Numbers might fail the eq? test. The fixnum 1 and the bignum 1e0 both represent 1 (one) but they are different types so they can’t be that similar.

Here we can use eqv? where we want to let some values be the same. Numbers and strings might be eqv?.

Finally, for compound values (pairs, arrays, has tables etc.) we need equal? to walk around the structures comparing element by element. Here, R5RS suggests:

A rule of thumb is that objects are generally equal? if they print the same.

Even this might not be enough in the general case. For example, some encryption algorithms will always produce a different digest every time they are invoked. These require a separate action to verify the digest is correct.

function eq? o1 o2

test if o1 and o2 are indistinguishable in memory

Param o1:

object to test

Type o1:

any

Param o2:

object to test

Type o2:

any

Return:

#t if o1 is eq? to o2, #f otherwise

function eqv? o1 o2

test if o1 and o2 are equivalent

Numbers and strings can be different in memory but have the same value.

Param o1:

object to test

Type o1:

any

Param o2:

object to test

Type o2:

any

Return:

#t if o1 is eqv? to o2, #f otherwise

function equal? o1 o2

test if o1 and o2 are semantically the same

R5RS suggests that the values print the same.

Param o1:

object to test

Type o1:

any

Param o2:

object to test

Type o2:

any

Return:

#t if o1 is equal? to o2, #f otherwise

Last built at 2024-12-21T07:10:38Z+0000 from 62cca4c (dev) for Idio 0.3.b.6