Newsgroups: comp.lang.clos
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!gatech!bloom-beacon.mit.edu!news.bu.edu!olivea!koriel!wnoc-sfc-news!hskgw.hitachi-sk.co.jp!cet.hsk!ori!phe!ysumi
From: ysumi@phe.hitachi-sk.co.jp (Yutaka Sumi)
Subject: conceivable meta-class libraries and standardization
Date: Tue, 6 Dec 1994 22:03:29 GMT
Nntp-Posting-Host: hokt.phe.hitachi-sk.co.jp
Organization: Hitachi Software Engineering Co.,Ltd., Yokohama, Japan
Sender: news@phe.hitachi-sk.co.jp (News Administrator)
Message-ID: <YSUMI.94Dec6170329@hokt.phe.hitachi-sk.co.jp>
Lines: 140


 I developped several meta-classes and used them to build an
inference system. Now I'm interested in conceivable meta-class
libraries and standardization of them. But I've rarely hard 
someone discussing it. I'd like to start the discussion
introducing the meta-classes each other. 

First of all, I'd like to introduce some of the features of
my meta-classes.
Any suggestions or advice are welcome.

 I found the slot options of the standard class too primitive
to build the inference system. So I decided to extend it using
MOP. As you know, :initform and :initargs are used for slot initialization.
And the :initfunction is created from :initform. The content of
:initfunction is a function with no parameter.
But I wanted someting like :parameterized-initfunction, or,
:initfunction-with-arg.
The coding image is as follows:
============================================================
(defclass class-A ()
   ((slot1  :initarg :slot1
            :initfunction-with-arg 
             #'(lambda (source-of-slot-value)
                  (parse-and-construct-the-value-of-the-slot
                      source-of-slot-value))))
   (:metaclass my-metaclass))
(make-instance 'class-A
   :slot1 '((rain is plenty)(sunshine is good)(harvest is good)))
============================================================
In the example, '((rain is plenty)(sunshine is good)(harvest is good))
is passed to the function defined at :initfunction-with-arg.
Then the return value is stored in the slot.
 This is not so bad. But it's still primitive. So, I kept refining it
regarding the points as follows:
(1)In many cases I could express the parameterized initfunction 
   in a declarative way. I don't think definition by a procedure is
   readable or a proper way.
(2)A class can inherit the parameterized initfunction 
   by implementing compute-effective-slot-definition. But the way
   to inherit is limited if it's a procefure.  Only either supercedence 
   or concatenation of the parameterized initfunction is possible. It's 
   impossible to merge the *features* of the parameterized initfunctions.
(3)I could categorize the possible parameterized initfunctions
   into a generalization hierarchy. Note that there are two hierarchies.
   One is the hierarchy of parameterized initfunctions. The other is 
   the hierarchy of the aplication classes.
(4)Often it's not proper to store the return value into the slot.
   For example, in the inference system associations among classes
   are implemented as a set of multi-methods and links among objects
   are implemented as CLOS objects. To establishe a link a certain
   protocol is required. You cannot just store the pointer to the
   object in the slot.
(5)Often it's better to define an association in the slot than 
   to define a parameterized initfunction. Generally speaking,
   an association between two classes should be defined apart 
   from the classes. But if the association is a relation of 
   aggregation, it's simpler to define it in a slot of the owner
   class. And both the parameterized initfunction and a set
   of multi-methods which are for association can be generated
   from an association object which is stored in the slot 
   definiton meta-object.
(6)To deal with forward reference, multi-phase constructor is 
   necessary. So, "when invoke" should be specified at the slot.

 Considering these points, I devised a parameterized initfunction 
meta-object system. An example is:
============================================================
(defclass fuzzy-predicate (component)
   ((membership-function)
    (attribute-name :initfunction-def (simple-init :funcs '(first)))
    (predicate-name :initfunction-def (simple-init :funcs '(third)))

(defclass class-A (super-class-of-A)
   ((fuzzy-predicates  
     :initfunction-def (objs-init-def)))
   (:metaclass my-metaclass))
(make-instance 'class-A
   :fuzzy-predicates
    '((rain is plenty)(sunshine is good)(harvest is good)))
============================================================
(objs-init-def) is the definition of the initfunction meta-object.
The reader method and :initarg of the slot are generated 
from the meta-object. You can supress them by passing parameters
to (objs-init-def) if necessary. Or, you can use another 
initfunction meta-object which doesn't generate them.
A set of multi-methods which is the implementation of the 
association between class-A and fuzzy-predicate is generated. 
(objs-init-def) get the name of the opponent class from
the name of the slot by default. In this example, the slot
name without "s" is used as the class name. the class name 
should be passed explicitly when the name 
of the slot is not the name of the class with "s". e.g.:
============================================================
((fuzz-pred  
   :initfunction-def 
     (objs-init-def :class 'fuzzy-predicate))) 
============================================================
The default link object of (objs-init-def) is agg-link,
which means aggregation link. The operation which establishes
the link is:
============================================================
(connect 'agg-link  
   <an-instance-of-class-A>  <an-instance-of-fuzzy-predicate>)
============================================================
The operation 
(1)stores <an-instance-of-class-A> in the list in the slot
owner of <an-instance-of-fuzzy-predicate>
(2)stores <an-instance-of-fuzzy-predicate> in the list in the slot
fuzzy-predicates of <an-instance-of-class-A>
(3)stores the link object in the subslot link of the slot owner
of <an-instance-of-fuzzy-predicate>
(4)stores the link object in the subslot link of the slot fuzzy-predicates
of <an-instance-of-class-A> .

The parameterized initfunction which is generated from (objs-init-def) does
(1)(make-instance 'fuzzy-predicate :_source '(rain is plenty))
(2)(connect 'agg-link  ......)
for the each definition of the fuzzy-predicate objects which
are passed as the parameter.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

A lot of important things are omitted in the explanation.
I want to post some of them later.
Especially, 
(1)the problem of parse and slot construction
(2)multi-phase object construction
(3)recognition of self during construction
(4)initfunction meta-object hierarchy
(5)merge of initfunction meta-objects
are worth while discussing.

Any suggestions or comments are welcome.

--
Yutaka Sumi (ysumi@phe.hitachi-sk.co.jp)
Hitachi Software Engineering Co., Ltd.
549-6, Shinano-machi, Totsuka-ku,Yokohama, 244 Japan
Tel:+81-45-824-2111    Fax:+81-45-826-8302
