[plt-scheme] equal? operator
Matthew Flatt schreef:
>Ok, but I'm still missing something, because I don't see how the table
>accomplishes anything. In particular, ekeeping the key maintains the
>mapping to the weak box, but it doesn't keep the weak box from getting
>emptied.
>
>
Ok, another example session (see below).
/"A *weak box* is similar to a normal box (see section 3.10
<http://download.plt-scheme.org/doc/mzscheme/mzscheme-Z-H-3.html#node_sec_3.10>),
but when the automatic memory manager can prove that the content value
of a weak box is only reachable via weak boxes, the content of the weak
box is replaced with |#f|."
/
As I see it, in the example below, a, b and c all point to the memory
"contained" in the weak box. As long as a, b and c exist, the contents
of the weak box will never be removed. And that is exactly what
I want.
You see, what happens is as follows:
1. psearch actually does a RPC via TCP/IP on localhost, port 4001.
telnetting on localhost port 4001 gives the following session:
(OODB "LPW0251.strader.xs4all.nl" 0.1 "oodb-backend-sqli" 0.1 1)
(search (all (illness-class-category)) ())(ok
((59872449310226502864700443097271
illness-class-category)))
2. The result: ((59872449310226502864700443097271 illness-class-category))
indicates that OID 59...271 is of class illness-class-category.
3. Next, an object of class illness-class-category is instantiated with
'from-oid OID. This instantiates
a class illness-class-category with default parameters.
4. Now I store (list OID) in the instantiated object and I put the
object in a weak box. The (list OID)
of object I use as key in the hash table.
5. When I retrieve another ((59872449310226502864700443097271
illness-class-category))
from the server, I first look for (list OID) in the hash table. HEY,
there's an object already there, I'll use
this one instead of allocating a new one.
Now, what I've effectivly reached, is that within the same running
instance of an application, two objects
of the same OID, which are eq? in the object oriented database (OODB)
I've created, are also eq? in
the running instance. And that's just what I wanted. Thanks to Eli's input!
> (require "proos.scm")
> (require "oodb-ci.scm")
> (oodb-ci-initialize "localhost" "hans" "" 4001)
#t
> (require "zk-classes.scm")
> (define a (car (psearch (all illness-class-category))))
PROOS-STORE: 59872449310226502864700443097271 #f #f
PROOS-STORE: 59872449310226502864700443097271 #roos
> (define b (car (psearch (all illness-class-category))))
PROOS-STORE: 59872449310226502864700443097271 #<weak-box> #roos
> b
#roos
> (eq? a b)
#t
> (-> a name)
"ok"
> (-> b name)
"ok"
> (-> a name "new name")
ok-put!
> (-> b name)
"new name"
> (collect-garbage)
> (define b (car (psearch (all illness-class-category))))
PROOS-STORE: 59872449310226502864700443097271 #<weak-box> #roos
> (collect-garbage)
> (define b (car (psearch (all illness-class-category))))
PROOS-STORE: 59872449310226502864700443097271 #<weak-box> #roos
> (collect-garbage)
> (define c (car (psearch (all illness-class-category))))
PROOS-STORE: 59872449310226502864700443097271 #<weak-box> #roos
> c
#roos
> (set! a 0)(set! b 0)(set! c 4)
> > > (define c (car (psearch (all illness-class-category))))
PROOS-STORE: 59872449310226502864700443097271 #<weak-box> #roos
> c
#roos
> (-> c name)
"new name"
(-> c illness-classes)
PROOS-STORE: 163698054800566253127307108927946 #f #f
PROOS-STORE: 163698054800566253127307108927946 #roos
PROOS-STORE: 163698054800566253127307108927945 #f #f
PROOS-STORE: 163698054800566253127307108927945 #roos
PROOS-STORE: 163698054800566253127307108927944 #f #f
PROOS-STORE: 163698054800566253127307108927944 #roos
PROOS-STORE: 134167358730453000620204068929124 #f #f
PROOS-STORE: 134167358730453000620204068929124 #roos
PROOS-STORE: 132069009480453002472005822925980 #f #f
PROOS-STORE: 132069009480453002472005822925980 #roos
PROOS-STORE: 132069009480453002472005822925979 #f #f
PROOS-STORE: 132069009480453002472005822925979 #roos
PROOS-STORE: 132069009480453002472005822925978 #f #f
PROOS-STORE: 132069009480453002472005822925978 #roos
PROOS-STORE: 101069891380339751816804499004492 #f #f
PROOS-STORE: 101069891380339751816804499004492 #roos
PROOS-STORE: 68254699550226382758901006667984 #f #f
PROOS-STORE: 68254699550226382758901006667984 #roos
PROOS-STORE: 63721520500226501175203246565420 #f #f
PROOS-STORE: 63721520500226501175203246565420 #roos
(#roos #roos #roos #roos #roos #roos #roos #roos #roos #roos)
> (define b (car (-> c illness-classes)))
PROOS-STORE: 163698054800566253127307108927946 #<weak-box> #roos
PROOS-STORE: 163698054800566253127307108927945 #<weak-box> #roos
PROOS-STORE: 163698054800566253127307108927944 #<weak-box> #roos
PROOS-STORE: 134167358730453000620204068929124 #<weak-box> #roos
PROOS-STORE: 132069009480453002472005822925980 #<weak-box> #roos
PROOS-STORE: 132069009480453002472005822925979 #<weak-box> #roos
PROOS-STORE: 132069009480453002472005822925978 #<weak-box> #roos
PROOS-STORE: 101069891380339751816804499004492 #<weak-box> #roos
PROOS-STORE: 68254699550226382758901006667984 #<weak-box> #roos
PROOS-STORE: 63721520500226501175203246565420 #<weak-box> #roos
> (proos-store->list)
(((163698054800566253127307108927944) #<weak-box>)
((101069891380339751816804499004492) #<weak-box>)
((134167358730453000620204068929124) #<weak-box>)
((68254699550226382758901006667984) #<weak-box>)
((132069009480453002472005822925979) #<weak-box>)
((132069009480453002472005822925980) #<weak-box>)
((59872449310226502864700443097271) #<weak-box>)
((132069009480453002472005822925978) #<weak-box>)
((63721520500226501175203246565420) #<weak-box>)
((163698054800566253127307108927946) #<weak-box>)
((163698054800566253127307108927945) #<weak-box>))
> (collect-garbage)
> (proos-store->list)
(((59872449310226502864700443097271) #<weak-box>)
((163698054800566253127307108927946) #<weak-box>))
> (set! c 0)
> (proos-store->list)
(((59872449310226502864700443097271) #<weak-box>)
((163698054800566253127307108927946) #<weak-box>))
> (collect-garbage)
> (proos-store->list)
(((163698054800566253127307108927946) #<weak-box>))
> b
#roos
(-> b poid)
163698054800566253127307108927946
> (set! b 2)
> (collect-garbage)
> (proos-store->list)
()
>
**********************************************************
as for the class definitions
**********************************************************
(def-pclass
(this (illness-class-category . args))
(default)
(supers)
(private)
(persistent
name
z-order
)
(public
(define (illness-classes)
(psearch (= (illness-class category-oid) (poid this))))
(define (add-illness-class obj)
(-> obj category-oid (poid this)))
)
(constructor)
)
(def-pclass
(this (illness-class . args))
(default)
(supers)
(private)
(persistent
_category
category-oid
name
color-fg
color-bg
font
)
(public
(define (category . cat)
(if (not (null? cat))
(begin
(-> this _category (car cat))
(-> (car cat) add-illness-class this)))
(-> this _category))
)
(constructor)
)
>Are `a' and `b' keys here?
>
>
No, the're the (Persistent) ROOS objects.
>Ok, but is what's in the weak box --- an object or #f?
>
>
As can be seen from the previous section. Still the object.
>Looking back at your problem description, maybe what I'm missing is
>that it's ok for for the weak box to be emptied, because this table
>implements a cache?
>
>
Well it sort of creates a cache. As long as there are "living" objects
of a certain OID, the
cache won't be collected. When all objects of a certain OID cease to
exist, it is collected.
>
>
>>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?
>>
>>
Ok, but then I'll have to convert a number to a symbol each time. I
wonder what is more expensive?
Note that the numbers I use are fairly large. Doesn't that open
possibilities?
>Using symbols instead of numbers might be the right trade-off. Symbols
>are allocated and collected, like lists, but they are also interned,
>like small integers.
>
>Matthew
>
>
>
Thanks,
Hans
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20051122/fc1c127c/attachment.html>