Lisp HUG Maillist Archive

MOP Multiple Metaclass Inheritance?

Hi all,

Been doing some persistent object stuff here, and MOP works like a champ. But I have run into a situation where some objects contain persistent slots AND some slots that are "virtual" in the sense that their reader returns values computed on the basis of the values contained in other slots, some of which are persistent.

So I defined a PERSISTENT-METACLASS to handle objects containing persistent slots, and a COMPUTABLE-METACLASS to handle objects containing computable slots. Both work great. 

But now, in order to produce objects that contain both kinds of slots, I had to stack the metaclasses so that COMPUTABLE-METACLASS inherits from STANDARD-CLASS, and then have PERSISTENT-METACLASS inherit from COMPUTABLE-METACLASS -- even though there is really nothing about the two metaclasses that should warrant an inheritance relationship between them.

;; --------------------------------------------------------------
;; metaclass of objects that might contain computed slots

(defclass computed-metaclass (#+:LISPWORKS clos:standard-class
                              #+:ALLEGRO clos::standard-class)
  ())

;; --------------------------------------------------------------
;; metaclass of objects that might contain persistent slots

(defclass persistent-metaclass (computed-metaclass) ;; ??
  ())

;; --------------------------------------------------------------

We can do multiple inheritance at the CLOS level. But what about at the MOP Meta-level where we have to declare our new class definition's :metaclass ??

Dr. David McClain
Chief Technical Officer
Refined Audiometrics Laboratory
4391 N. Camino Ferreo
Tucson, AZ  85750

email: dbm@refined-audiometrics.com
phone: 1.520.390.3995
web: http://www.refined-audiometrics.com



Re: MOP Multiple Metaclass Inheritance?


On 2 Dec 2008, at 05:39, David McClain wrote:

Hi all,

Been doing some persistent object stuff here, and MOP works like a champ. But I have run into a situation where some objects contain persistent slots AND some slots that are "virtual" in the sense that their reader returns values computed on the basis of the values contained in other slots, some of which are persistent.

So I defined a PERSISTENT-METACLASS to handle objects containing persistent slots, and a COMPUTABLE-METACLASS to handle objects containing computable slots. Both work great. 

But now, in order to produce objects that contain both kinds of slots, I had to stack the metaclasses so that COMPUTABLE-METACLASS inherits from STANDARD-CLASS, and then have PERSISTENT-METACLASS inherit from COMPUTABLE-METACLASS -- even though there is really nothing about the two metaclasses that should warrant an inheritance relationship between them.

;; --------------------------------------------------------------
;; metaclass of objects that might contain computed slots

(defclass computed-metaclass (#+:LISPWORKS clos:standard-class
                              #+:ALLEGRO clos::standard-class)
  ())

;; --------------------------------------------------------------
;; metaclass of objects that might contain persistent slots

(defclass persistent-metaclass (computed-metaclass) ;; ??
  ())

;; --------------------------------------------------------------

We can do multiple inheritance at the CLOS level. But what about at the MOP Meta-level where we have to declare our new class definition's :metaclass ??

Easy:

(defclass computed-class (standard-class) ()) ;; don't say 'metaclass' here, we're already at the metalevel ;)
(defclass persistent-class (standard-class) ())

...and then...

(defclass computed-persistent-class (computed-class persistent-class) ())

...and later...

(defclass person-object #|!!!|# (...)
  ()
  (:metaclass computed-persistent-class))

It would have been nice if one could say this instead:

(defclass person-object ()
  ()
  (:metaclasses computed-class persistent-class))

However, it's unlikely that such automatic compositions of metaclasses automagically work - you typically have to do some non-trivial adaptations, for example for the slot-value-using-class protocol, etc.

You can take a look at the ContextL source code, where I use this kind of manual metaclass composition to define the new features separately from each other.


Pascal

-- 
Pascal Costanza, mailto:pc@p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium








Updated at: 2020-12-10 08:41 UTC