[plt-scheme] equal? operator

From: Hans Oesterholt-Dijkema (hdnews at gawab.com)
Date: Tue Nov 22 01:58:24 EST 2005

Hi Matthew,

You are right. I put the wrong code in the example. Please look at this 
code:

(define PROOS-STORE (make-hash-table 'equal 'weak))

(define (pobject-from-oid oid _class)
  (let ((class (proos-class _class)))
    (if (eq? class #f)
    (error (string-append "proos class definition for " (symbol->string 
_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 (-> obj list-poid) (make-weak-box obj))
        (oodb-dbg "PROOS-STORE: " oid obj)
        obj)
          (weak-box-value obj))))))

And the session in emacs below:

Welcome to MzScheme version 299.403, Copyright (c) 2004-2005 PLT Scheme, 
Inc.
 > > > #t
 > (require "zk-classes.scm")
 > (define a (car (psearch (all illness-class-category))))
 > (define b (car (psearch (all illness-class-category))))
 > (proos-store->list)
(((59872449310226502864700443097271) #<weak-box>))
 > (collect-garbage)
 > (proos-store->list)
(((59872449310226502864700443097271) #<weak-box>))
 > (collect-garbage)
 > (proos-store->list)
(((59872449310226502864700443097271) #<weak-box>))
 > (set! a #f)
 > (set! b #f)
 > (collect-garbage)
 > (proos-store->list)
()


However when I don't use the (list) around the oid, It won't work. Isn't 
there a way without
the 'equal property on the hash table?

Matthew Flatt schreef:

>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
>
>_________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>  
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20051122/64ea138e/attachment.html>

Posted on the users mailing list.