[plt-scheme] equal? operator
On Nov 22, Hans Oesterholt-Dijkema wrote:
>
> > So, what I will do, is indead take your advice and try to create a
> > weak hash table holding
> > all the proos variables currently active in memory.
> >
> I implemented this:
>
> (define PROOS-STORE (make-hash-table 'equal 'weak))
>
> (define (proos-store->list)
> (hash-table-map PROOS-STORE
> (lambda (key val)
> (list key val))))
>
> (define (pobject-from-oid oid _class)
> (let ((class (proos-class _class)))
> (if (eq? class #f)
> (error (string-append "proos class definition for " _class " not
> found"))
> (let* ((obj (hash-table-get PROOS-STORE (list oid) (lambda () #f))))
> (oodb-dbg "PROOS-STORE: " oid obj)
> (if (eq? obj #f)
> (let ((obj (class 'from-oid oid)))
> (hash-table-put! PROOS-STORE (list oid) (make-weak-box obj))
> (oodb-dbg "PROOS-STORE: " oid obj)
> obj)
> (weak-box-value obj))))))
>
> oid's are 32<oid<64bit integers. I noticed a normal hash table
> (make-hash-table 'weak)
> will not find my oids (they're to big). Now I resorted to (list oid) for
> the key in the hash
> table *and* an 'equal property on the hash tables. But can It be done
> safely without the
> (list ...)?
Yes -- because `equal?' works fine on bigints. Also -- why to you
make weak boxes? -- The hash table stores values weakly anyay...
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!