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