<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Matthew,<br>
<br>
You are right. I put the wrong code in the example. Please look at this
code:<br>
<tt><br>
(define PROOS-STORE (make-hash-table 'equal 'weak))<br>
<br>
(define (pobject-from-oid oid _class)<br>
(let ((class (proos-class _class)))<br>
(if (eq? class #f)<br>
(error (string-append "proos class definition for "
(symbol->string _class) " not found"))<br>
(let* ((obj (hash-table-get PROOS-STORE (list oid) (lambda () #f))))<br>
(oodb-dbg "PROOS-STORE: " oid obj)<br>
(if (eq? obj #f)<br>
(let ((obj (class 'from-oid oid)))<br>
(hash-table-put! PROOS-STORE (-> obj list-poid)
(make-weak-box obj))<br>
(oodb-dbg "PROOS-STORE: " oid obj)<br>
obj)<br>
(weak-box-value obj))))))<br>
<br>
</tt>And the session in emacs below:<br>
<br>
<tt>Welcome to MzScheme version 299.403, Copyright (c) 2004-2005 PLT
Scheme, Inc.<br>
> > > #t<br>
> (require "zk-classes.scm")<br>
> (define a (car (psearch (all illness-class-category))))<br>
> (define b (car (psearch (all illness-class-category))))<br>
> (proos-store->list)<br>
(((59872449310226502864700443097271) #<weak-box>))<br>
> (collect-garbage)<br>
> (proos-store->list)<br>
(((59872449310226502864700443097271) #<weak-box>))<br>
> (collect-garbage)<br>
> (proos-store->list)<br>
(((59872449310226502864700443097271) #<weak-box>))<br>
> (set! a #f)<br>
> (set! b #f)<br>
> (collect-garbage)<br>
> (proos-store->list)<br>
()<br>
<br>
<br>
</tt>However when I don't use the (list) around the oid, It won't work.
Isn't there a way without<br>
the 'equal property on the hash table?<br>
<br>
Matthew Flatt schreef:
<blockquote cite="mid20051122015712.4644A15B5A9@salt.cs.brown.edu"
type="cite">
<pre wrap="">At Tue, 22 Nov 2005 01:31:44 +0100, Hans Oesterholt-Dijkema wrote:
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">(define PROOS-STORE (make-hash-table 'equal 'weak))
[...]
(hash-table-put! PROOS-STORE (list oid) (make-weak-box obj))
[...]
</pre>
</blockquote>
</blockquote>
</blockquote>
<pre wrap=""><!---->
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.
</pre>
<blockquote type="cite">
<pre wrap=""> >(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)
()
</pre>
</blockquote>
<pre wrap=""><!---->
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.
</pre>
<blockquote type="cite">
<pre wrap="">In my case, there's a circular reference. The oid is stored in the
object created by (class 'from-oid oid).
</pre>
</blockquote>
<pre wrap=""><!---->
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
_________________________________________________
For list-related administrative tasks:
<a class="moz-txt-link-freetext" href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a>
</pre>
</blockquote>
<br>
</body>
</html>