[plt-scheme] Another question: eq? and eqv?

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Fri Dec 30 19:09:00 EST 2005

Greg Woodhouse wrote:

>I understand that eq? is supposed to compare objects for identity (like
>comparing pointers) and equal? compares objects for value. I also
>understand that equal? recursively applies eqv? to the components of a
>structure. What is less clear to me is how eq? and eqv? differ. When is
>(eq? a b) different from (eqv? a b) ?

*Prof. R. Fateman*

	Oct 3 2004, 3:48 pm   show options 

Newsgroups: *ucb.class.cs61a*
From: *"Prof. R. Fateman" <fate... 
- Find messages by this author 

Date: *Sun, 03 Oct 2004 07:48:08 -0700*
Local: *Sun, Oct 3 2004 3:48 pm *
Subject: *Re: eq? & eqv? qustion*
Reply to Author 
| Forward 
| Print 
| Individual Message 
| Show original 
| Report Abuse 

Question wrote:
 > I have read "Revised report on the Algorithmic language *Scheme*", but I
 > am still confused about the difference between *eq*? and *eqv*? . the 
 > thing I knew was that *eq*? is the finest discriminating, and equal? is
 > the coarsest, *eqv*? is in between. But this statement doesn't 
provide me
 > "WHAT" the distinctions are.

 > Please provide me some cases that for the same argument, *eq*? and 
 > evaluates differently.

Richard Fateman answered this in a usenet post once:

(define a (list 1 2))

(define b (list 1 2))

(*eq*? a b)
(*eqv*? a b)
(*eq*? a a)

It's like this.  If you were on the beach and you saw a
Great White Shark X in the water, and a hour later someone
else saw a Great White Shark Y in the water, and then
two hours later someone killed a Great White Shark Z
in the water,  you would very much like to know if

(and (*eq*? X Y) (*eq*? Y Z)) ; there was only one shark seen, and it is 


(and (*eqv*? X Y) (*eqv*? Y Z)) ; there may be one, two, or three 
sharks, all Great White Sharks.

; one of them is dead.

You mostly use *eqv*?  and equal?   in this course.

You can use *eq*?  if you are comparing symbolic atoms, or if you really
care to make a case that THIS '(a b c)  and THAT '(a b c) are different
even though their corresponding subparts are *eq*.  or that
if (define whale '(a b c))   ..  (*eq*?  whale whale)  but not (*eq*? 
whale (cons 'a '(b c)))

Jens Axel Søgaard

Posted on the users mailing list.