[plt-scheme] equal? operator
At Tue, 22 Nov 2005 01:31:44 +0100, Hans Oesterholt-Dijkema wrote:
>
> >>(define PROOS-STORE (make-hash-table 'equal 'weak))
> >>
> >>[...]
> >> (hash-table-put! PROOS-STORE (list oid) (make-weak-box obj))
> >>[...]
This doesn't look right. Nothing refers to the key created for the
hash-table key (since it's a list created right at at the time that the
mapping is installed), so the value should be immediately subject to
collection.
> >(define a (car (psearch (all test-class))))
> >(define b (car (psearch (all test-class))))
> >(eq? a b)
> #t
> >(proos-store->list)
> ((23423523523234342 <weak-box>))
> >(set! a #f)
> >(set! b #f)
> >(collect-garbage)
> >(proos-store->list)
> ()
What happens if you skip the two `set!'s? Maybe it will require an
extra `collect-garbage', but unless I'm missing something, you should
still get an empty list.
> In my case, there's a circular reference. The oid is stored in the
> object created by (class 'from-oid oid).
This is called the "key in value" problem. In 299.403 and later, you
can solve it using ephemerons (where you're currently using weak
boxes).
Matthew