[plt-scheme] Another question: eq? and eqv?
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
<http://groups.google.com/group/ucb.class.cs61a/browse_thread/thread/dcb9af2576a8a526/8d768b60b777b61e?lnk=st&q=scheme+eqv%3F+eq%3F&rnum=7&hl=en#>
Newsgroups: *ucb.class.cs61a*
From: *"Prof. R. Fateman" <fate...
<http://groups.google.com/groups/unlock?msg=d72976ddc16fee36&hl=en&_done=/group/ucb.class.cs61a/browse_thread/thread/dcb9af2576a8a526/8d768b60b777b61e%3Flnk%3Dst%26q%3Dscheme%2Beqv%253F%2Beq%253F%26rnum%3D7%26hl%3Den>@cs.berkeley.edu>*
- Find messages by this author
<http://groups.google.com/groups?enc_author=_B6wGhcAAAAHapzCOXnYJpzs1OVOfa4YORUl-xI19U1qrau6OMMmew&scoring=d&hl=en>
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
<http://groups.google.com/group/ucb.class.cs61a/post?hl=en&inreplyto=d72976ddc16fee36&reply_to=author&_done=%2Fgroup%2Fucb.class.cs61a%2Fbrowse_thread%2Fthread%2Fdcb9af2576a8a526%2F8d768b60b777b61e%3Flnk%3Dst%26q%3Dscheme+eqv%3F+eq%3F%26rnum%3D7%26hl%3Den%26&>
| Forward
<http://groups.google.com/group/ucb.class.cs61a/post?hl=en&inreplyto=d72976ddc16fee36&forward=1&_done=%2Fgroup%2Fucb.class.cs61a%2Fbrowse_thread%2Fthread%2Fdcb9af2576a8a526%2F8d768b60b777b61e%3Flnk%3Dst%26q%3Dscheme+eqv%3F+eq%3F%26rnum%3D7%26hl%3Den%26&>
| Print
<http://groups.google.com/group/ucb.class.cs61a/msg/d72976ddc16fee36?dmode=print&hl=en>
| Individual Message
<http://groups.google.com/group/ucb.class.cs61a/msg/d72976ddc16fee36?hl=en&>
| Show original
<http://groups.google.com/group/ucb.class.cs61a/msg/d72976ddc16fee36?dmode=source&hl=en>
| Report Abuse
<http://groups.google.com/groups/abuse?hl=en&group=ucb.class.cs61a&url=http%3A%2F%2Fgroups.google.com%2Fgroup%2Fucb.class.cs61a%2Fmsg%2Fd72976ddc16fee36>
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
only
> 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
*eqv*?
> 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
dead.
versus
(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