<div dir="ltr">The hash tables seem fine to me, but maybe we need a better example.<div><br></div><div><div>#lang racket</div><div><br></div><div>(struct cpd (x y))</div><div><br></div><div>(define C1 (cpd 1 "bla"))</div>
<div>(define C2 (cpd 1 "bla"))</div><div><br></div><div>(equal? C1 C2)</div><div>#f</div><div><br></div><div>(define ht (make-hash))</div><div>(hash-set! ht C1 1)</div><div>(hash-set! ht C2 2)</div><div>(equal? (hash-ref ht C1)</div>
<div> (hash-ref ht C2))</div><div>;; produces #f</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Dec 28, 2013 at 5:34 PM, Sam Tobin-Hochstadt <span dir="ltr"><<a href="mailto:samth@cs.indiana.edu" target="_blank">samth@cs.indiana.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">While your answer is what Manfred is looking for, I still find the original behavior worrying. It lets you expose the internals of opaque data structures without having the relevant inspector.</p>
<span class="HOEnZb"><font color="#888888">
<p dir="ltr">Sam</p></font></span><div class="HOEnZb"><div class="h5">
<div class="gmail_quote">On Dec 28, 2013 4:16 PM, "J. Ian Johnson" <<a href="mailto:ianj@ccs.neu.edu" target="_blank">ianj@ccs.neu.edu</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
You want to make sure your structs are inspectable. You can define your structs with the #:transparent option or define your own equality relation with the gen:equal+hash generic interface.<br>
-Ian<br>
----- Original Message -----<br>
From: Manfred Lotz <<a href="mailto:manfred.lotz@arcor.de" target="_blank">manfred.lotz@arcor.de</a>><br>
To: <a href="mailto:users@racket-lang.org" target="_blank">users@racket-lang.org</a><br>
Sent: Sat, 28 Dec 2013 15:41:28 -0500 (EST)<br>
Subject: [racket] hash table confusion<br>
<br>
I have a hash table (created by using make-hash) where the key is a<br>
struct. This seems to work fine although the documentation says<br>
The make-hash procedure creates a table where keys are compared with<br>
equal?,...<br>
<br>
and it seems that equal? gives #f if I compare two structs having the<br>
same contents:<br>
<br>
<br>
(struct cpd (x y))<br>
<br>
(define C1 (cpd 1 "bla"))<br>
(define C2 (cpd 1 "bla"))<br>
<br>
(equal? C1 C2)<br>
#f<br>
<br>
<br>
Why does my hash table work fine? In my hash handling I'm using<br>
make-hash, hash-ref!, hash-set!, hash-for-each.<br>
<br>
--<br>
Manfred<br>
<br>
<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>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</blockquote></div>
</div></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></div>