[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Self-indexing class?!



At 12:10 PM 5/16/95, Ken Tilton wrote:
>I have this wacky idea of implementing a dataset as a self-indexing class
>to store tables of data that constitute the "beef" of my app.
>
>Each instance has a "key" slot. The class has a shared slot for a
>hash-table of class-instances. initialize-instance gets an after method
>that adds any instance to the hash table.
>
>1> Is this a dumb idea?

One thing to watch out for is that you'll make it impossible
to ever garbage collect any instances of your class. This may
be what you want. If not, you might want to use a weak hash table.

>
>2> Would anyone know how much this would break Wood?

Wood doesn't persistently store class slots, so your index will
not be persistent unless you write code to specifically update
the disk version of the index. Since you need to explicitly store
the instance anyway, this shouldn't be a problem.

>
>3> Uh, how do I get to the hash-table! (Without a dummy instance to go through.)
>#'slot-value-using-class had my pulse pounding until I saw (a) MCL don't
>support it and (b) AMOP does not say the obj arg can be nil, which is what
>I would have to do.

Use class-prototype, a part of the Metaobject protocol:

? (defclass bar ()
    ((class-slot :accessor bar-class-slot
                 :allocation :class
                 :initform 'bar)))
#<STANDARD-CLASS BAR>
? (bar-class-slot (class-prototype (find-class 'bar)))
BAR
?