[elephant-devel] Query System
Ian Eslick
eslick at media.mit.edu
Wed May 14 18:15:44 UTC 2008
Hi Daniel,
Welcome to the Metaobject Protocol, aka the MOP! There is a rich
embedded language for introspecting over and manipulating the class
system in lisp that Elephant uses heavily. You could have a procedure
extract the and caches the essential information from the class slot
definitions into a little structure. You can do this the first time
the query system encounters a class, and add a hook into the class
instantiation code that invalidates the cache on class redefinition.
It's worth diving into it, but it can take awhile to wrap your head
around the concepts, not to mention the idiosyncrasies of the MOP.
I'm happy to review your proposal offline or online as you prefer.
If you look at src/elephant/package.lisp we import symbols selectively
from the metaobject protocol package specific to each lisp. The
functions you are looking for are:
class-slots - return a list of slot-definition-objects
Each of the special elephant slots returned by this function is a
subtype of the class standard-effective-slot-definition and persistent-
effective-slot-definition. Direct slots are representations of the
arguments to the defclass form. Effective slots are computed when the
class is 'finalized' (i.e. the first instance is instantiated and it's
inheritance hierarchy is fully defined). A generic function called
slot-definition-using-class dispatches on the type of the effective
slot to implement the common-lisp primitive (slot-value obj slotname)
The special types you'll care about are:
- persistent-effective-slot-definition
persistent-p is a predicate on the slot definition that tells you
if it is an instance of or subclass of a persistent slot.
- indexed-effective-slot-definition
(has special slots named: indices and base-class; predicate is
indexed-p)
- derived-effective-slot-definition
(derived from the index slot also contains a slot: fn for
determining the value to index on)
- set-valued-effective-slot-definition
(slot stores a reference to a pset; set-valued-p)
- association-effective-slot-definition
(association-p; this is complicated so we should handle this as a
special case in the query system later)
I have accessors to get these slots from the class object such as
association-slot-defs, indexed-slot-defs, and persistent-slot-defs.
Read metaclasses.lisp for more information on these definitions.
If you know an index exists on a class slot, you can simply call (find-
inverted-index class-object slotname) to have the system fetch it for
you.
This should be enough for you to define a structure like:
(defstruct class-info classname slotypes)
Where slottypes is an alist:
- ((slotname . :indexed) (slotname . :persistent)
(slotname . :transient))
or something like that.
Ian
On May 14, 2008, at 1:45 PM, lists at infoway.net wrote:
> I've digested Ian and Leslie's comments on this thread and think
> we're all on the same page now. I've been reading different papers
> and other OODBMs in trying to propose a querying syntax and am
> pretty close to completing this now. However, I have some doubts for
> which I'll need someone's help with, which will allow me to continue
> drafting my proposal.
>
> I believe Ian (if it was someone else, I apologize for not quoting
> you) mentioned that we could, as a later phase, introspect the class
> and ask for the indices available in order to do some query
> optimizations. So my question goes somewhere along those lines and
> I'm wondering (please excuse my limited knowledge of Lisp and thank
> you for helping my learning curve) if it's possible to obtain the
> list of slots and/or slot-accessor functions for a given class.
>
> Thanks,
> Daniel
> _______________________________________________
> elephant-devel site list
> elephant-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/elephant-devel
More information about the elephant-devel
mailing list