in search of equality:
eq? and equal?


Given these definitions, what will eq? and equal? return when called on the pairs listed below?

  (define s "donut")
  (define t s)
  (define l (list 3 4))
  (define m (cons 3 '(4)))
  (define x (car l))
  (define y 3)

eq? equal?
  1. s and "donut"
  2. t and "donut"
  3. s and t
  4. m and (list 3 4)
  5. l and m
  6. x and y
  7. x and 3
false
false
true
false
false
true*
true*
.
.
.
all true
.
.
.

*Strictly speaking, under R5RS, the result of eq? in these two cases is not specified. For small numeric values, however, most implementations (including our beloved Dr. Scheme) will return true in this case. Using eqv? instead will always return true if the numbers are equal, regardless of how large the number is. See the "Equivalence predicates" section of R5RS for more details.


Ken Yasuhara <yasuhara@cs.washington.edu>
Last modified: Thu Jul 1 14:32:47 PDT 1999