No subject

From: ()
Date: Fri Jul 13 09:02:16 EDT 2012

Caveat concerning mutable keys: If a key in an equal?-based hash table is  
mutated (e.g., a key string is modified with string-set!), then the hash  
table’s behavior for insertion and lookup operations becomes unpredictable.

Try make-hasheq instead of make-hash, that should work here.



On Fri, 19 Oct 2012 17:57:41 +0200, Ted &lt;<A HREF="mailto:tedr56 at gmail.com">tedr56 at gmail.com</A>&gt; wrote:

&gt; Hi the list,
&gt; I was wondering for my midi/osc -&gt; event mapping project if it was
&gt; possible to put objects instances (with racket/class) as hash keys.
&gt; I tried and it worked. The problem is, I pushed further and when I
&gt; change object fields, the hash can't find my key anymore, despite I see
&gt; it in.
&gt;
&gt; For the record:
&gt;
&gt; (require racket/class)
&gt;
&gt; (define test%
&gt;     (class object%
&gt;         (inspect #f)
&gt;         (init-field
&gt;             address
&gt;         )
&gt;         (define/public (getAddress)
&gt;             address
&gt;         )
&gt;         (define/public (setAddress n)
&gt;             (set! address n)
&gt;         )
&gt;         (super-new)
&gt;     )
&gt; )
&gt;
&gt; (define testy (new test% (address 12)))
&gt; (define testH (make-hash))
&gt; (hash-set! testH testy (send testy getAddress))
&gt;
&gt;&gt; testH
&gt; #hash((#(struct:object:test% 12) . 12))
&gt;
&gt;&gt; (send testy setAddress 13)
&gt;&gt; testH
&gt; #hash((#(struct:object:test% 13) . 12))
&gt;&gt; (hash-has-key testH testy)
&gt; #f
&gt;&gt; (hash-ref testH testy)
&gt; hash-ref: no value found for key: (object:test% 13)
&gt;
&gt; That's an odd response. I know it's an odd request too, but if anyone
&gt; could help me on this, even it I have to use an other solution.
&gt;
&gt; Thanks in advance.
&gt;
&gt; Ted

____________________
  Racket Users list:
  <A HREF="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</A>
</PRE>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>

--=-VzqbN62KVWh3iXLUaK1N--


Posted on the users mailing list.