[plt-scheme] equal? operator

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Nov 21 20:57:11 EST 2005

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



Posted on the users mailing list.