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

Re: Status of the PCL's metaclass implementation

  To: commonloops.pa@xerox.com
  Subject: Status of the PCL's metaclass implementation
  Date: Mon, 07 Nov 88 19:19:53 PST
  From: shane%blackcomb@rand.org
  1]  Could someone give me a clear distinction between a
  superclass and a metaclass.  When would one want to use a 
  metaclass; and what baggage is required by metaclasses.
  ;;; --------------------
  ;;; I defined a metaclass as follows:
  ;;; --------------------
  <fcl 38> (defclass my-standard-class1 ()
  		   ((my-slot :accessor my-slot))
  	   (:metaclass standard-class))
  <fcl 39> (setq mcs1 (find-class 'my-standard-class1))
  #<Standard-Class MY-STANDARD-CLASS1 17447731> 
  <fcl 40> (describe mcs1)
  The class #<Standard-Class MY-STANDARD-CLASS1 17447731> is an instance of
  class #<Standard-Class STANDARD-CLASS 13024421>.
  Name:                  MY-STANDARD-CLASS1
  Class-Precedence-List: (MY-STANDARD-CLASS1 OBJECT T)
  Local-Supers:          (OBJECT)
  Direct-Subclasses:     NIL
  #<Standard-Class MY-STANDARD-CLASS1 17447731> 
  ;;; --------------------
  ;;; Then I tried to define another class such that my-slot is one of 
  ;;; the class' slots:
  ;;; --------------------
  <fcl 41> (defclass my-class1 () () 
  	   (:metaclass my-standard-class1))
  Error: No matching method for the generic-function #<Function
  EXPAND-DEFCLASS @ #x2b4599>,
  when called with arguments (#<MY-STANDARD-CLASS1 17473401> MY-CLASS1 NIL

The metaobject protocol is asking my-standard-class1 to handle
expand-defclass which it doesn't handle.  Your example below is built
on  standard-class which does handle it, so expand-defclass then works.
  ;;; --------------------
  ;;; Then I defined another class:
  ;;; --------------------
  <fcl 44> (defclass my-standard-class2 (standard-class)
  		   ((my-slot :accessor my-slot)))
This stands a chance of being a metaclass, but see below ...
  ;;; --------------------
  ;;; And again I tried to define another class such that my-slot is one of 
  ;;; the class' slots:
  ;;; --------------------
  <fcl 47> (defclass my-class2 () () 
  	   (:metaclass my-standard-class2))
  Error: The class #<Standard-Class OBJECT 13024201> was specified as a
  super-class of the class #<My-Standard-Class2 MY-CLASS2 17563731>;
  but the meta-classes #<Standard-Class STANDARD-CLASS 13024421> and
  #<Standard-Class MY-STANDARD-CLASS2 17503031> are incompatible.
  [1] <fcl 48> :zoom
  Evaluation stack:
Your class my-class2 is built on OBJECT which is has metaclass
standard-nclass.  PCL checks to see if it is ok to mix classes from 2
different metaclasses using check-super-metaclass-compatibility your
metaclass must provide a non nil response if this is OK.  This should
be better documented.

Since you want this most of the time, i use the following metaclass

(defclass compatible-class-mixin

(defmethod check-super-metaclass-compatibility
	   ((class compatible-class-mixin) (super standard-class))
  ;;; --------------------
  Obviously, neither one of these attempts worked.  Essentially what I 
  want is to be able to access the my-slot slot by:
  (setf (my-slot mc1) 'hello) => HELLO
  (my-slot mc1) => HELLO
Your approach is correct.  Try it again after adding the mixin.
  2]  When describing an instance, containing an unbound slot, is an
  error the proper response?  For instance,
  (defclass c1 () ((a)))
  (describe (make-instance 'c1)) =>
  #<C1 xxxxxxxx> is an instance of class #<Standard-Class C1 yyyyyyyy>:
   The following slots have :INSTANCE allocation:Error: The slot A is
  unbound in the object #<C1 xxxxxxxx>.
I believe patches for this have come over the list.  
  Thank you,
  Darrell Shane
  P.S> I am running 8/28/88 (beta rev 1) AAAI PCL under Franz Allegro 
  CL 3.0.1 [sun3].