<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div>Joe,<br><br></div>Perhaps a more pedestrian explanation might help. There is a difference between two items having the same value and two items being the same item.<br>
<br></div>equal? tests if its two items have the same value.<br><br></div>eq? tests if two items are the same item.<br><br></div>Using your example:<br><br>(define A (make-posn 4 5))<br>(define B (make-posn (+ 3 1) (- 6 1)))<br>
<br></div>Both A and B are items (in this case posns) that have the same value. Thus, (equals? A B) is true.<br><br></div>A and B, however, are not the same item (they are two different posns that happen to have the same value). Thus, (eq? A B) is false.<br>
<br></div>Consider:<br><br></div>(define C B)<br><br></div>Now, C and B are the same item (the same posn). Thus, (eq? C B) is true. As C and A are not the same posn, we have (eq? C A) is false. As you would expect (equal? C A) is true (because the have the same value).<br>
<br></div>eq? returning true suffices to know that equal? returns true (if two items are the same item, then clearly they have the same value). equal? returning true does not suffice to know what eq? returns (given that two different items may or may not have the same value).<br>
<br></div>This difference is not relevant for most of HtDP, because it is not until your reach the material with assignment that you need to understand/know if two items are the same item or not. Before the assignment material, you are always testing for value equality.<br>
<br></div><div>Finally, eqv? is not used in HtDP and my advice would be to ignore its existence with beginners.<br></div><div><br></div>I hope this helps.<br><br></div>Marco<br><div><div><div><div><div><div><div><div><div>
<div><div><br><br></div></div></div></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 25, 2013 at 2:31 PM, Ford, Joe <span dir="ltr"><<a href="mailto:jford@hollandhall.org" target="_blank">jford@hollandhall.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>I have a group of high school students with a question... can someone please explain to beginner Racket users the differences between these three boolean functions: eq? equal? eqv?<br>
<br></div>
We have read the help menu verbage visible from DrRacket, but simply don't understand what it is saying. Maybe that's lack of context or vocabulary... but we're struggling a bit. To test simple variations of application, we wrote some simple code (shown below) but don't understand why the results are what they are:<br>
<br>(define FOUR "four")<br>(define A (make-posn 4 5))<br>(define B (make-posn (+ 3 1) (- 6 1)))<br>"-------------"<br>(equal? FOUR "four")<br>(equal? 4 (+ 1 3))<br>(equal? 4 (posn-x (make-posn 4 3)))<br>
(equal? A B)<br>"-------------"<br>(eq? FOUR "four")<br>(eq? 4 (+ 1 3))<br>(eq? 4 (posn-x (make-posn 4 3)))<br>(eq? A B)<br>"---------------"<br>(eqv? FOUR "four")<br>(eqv? 4 (+ 1 3))<br>
(eqv? 4 (posn-x (make-posn 4 3)))<br>(eqv? A B)<br><br><br></div>Why in the world would the above-defined A and B be considered "equal?" but not "eq?" or "eqv?"?<span class="HOEnZb"><font color="#888888"><br clear="all">
<div><div><div>
<br>-- <br><div dir="ltr"><i>Joe Ford<br>
Technology Resources, Scheduling & Yearbook<br>
Holland Hall<br>
<a href="mailto:jford@hollandhall.org" target="_blank">jford@hollandhall.org</a><br><br></i><img alt=""><br><br></div>
</div></div></div></font></span></div>
<br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><br>Cheers,<br><br>Marco<br><br>Have a´¨)<br>¸.·´¸.·*´¨) ¸.·*¨)<br>(¸.·´ (¸.·´ * wonderful day! :)
</div>