From: Darryl Davis (RA)
Subject: change-class in CLOS
Date: 
Message-ID: <6381@m1.cs.man.ac.uk>
While i have used Common lisp for a while now, i am new to CLOS and have a few problems with
objects, changing classes and DEFMETHOD

The objects
i have a set of objects, most of which are specilaisations of a basic object.
Some are specialisations of more than one object
eg
(DEFCLASS class1 ()
        ( (input :initarg :input      :type string    :reader class1-input))
   (:documentation "The foundation Object"))

(DEFCLASS class2 ()
	( (table :intform NIL         :accessor class2-table))
   (:documentation "A secondary foundation Object"))

(DEFCLASS class3 ( class1 )
        ( (symbolist :intform NIL         :accessor class3-symbolist))
   (:documentation "A secondary level Object"))

(DEFCLASS class4 ( class3 class2 )
        ( (complexarg :intform NIL         :accessor class4-complexarg))
   (:documentation "A third level Object"))

The foundation object (ie objects of class1) is created in response to user input,
It becomes a different class of object on the basis of the parsed input.
 What i have problems with are these two situations:

1. 
where i have SomeOBJECT of class class3 and require it to become a class4 class object.
and i want it to inherit the current slot values of two objects.
the standard way of changing class goes like this:

(change-class SomeOBJECT 'class4)
and then set appropriate slot values according to the two objects i previously had
(of course it (by default) inherits the slot values of SomeOBJECT where they exist in the new object)

what i want is something like this:

(SETF NewOBJECT (change-class-special SomeOBJECT SomeFurtherObject 'class4))h

2.
The second problem is using DEFMETHOD with Multiple objects
eg

(DEFMETHOD some-special-process ((obj1 class1) (obj2 class2))
	......)

(DEFMETHOD some-special-process ((obj1 class1) (obj2 class4))
        ......)


Any ideas on these thorns would be appreciated

dr doom the optimist
--
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
   Dr. Darryl Davis                	>
   Multi-Media Laboratory		>
   Department of Electrical Engineering >   E-mail    	: ···@spec0.man.ac.uk
   The University of Manchester     	>             
   Brunswick St                      	>   Phone     	: (+44)-61-275-4561
   Manchester M13 9PL               	>   FAX 	: (+44)-61-275-4512
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
From: Barry Margolin
Subject: Re: change-class in CLOS
Date: 
Message-ID: <1b0agpINNj2q@early-bird.think.com>
In article <····@m1.cs.man.ac.uk> ···@spec0.ee.man.ac.uk (Darryl Davis (RA)) writes:
>While i have used Common lisp for a while now, i am new to CLOS and have a few problems with
>objects, changing classes and DEFMETHOD

CLOS questions are more appropriately posted to comp.lang.clos.  I've
redirected the discussion there.

>1. 
>where i have SomeOBJECT of class class3 and require it to become a class4 class object.
>and i want it to inherit the current slot values of two objects.
>the standard way of changing class goes like this:
>
>(change-class SomeOBJECT 'class4)
>and then set appropriate slot values according to the two objects i previously had
>(of course it (by default) inherits the slot values of SomeOBJECT where they exist in the new object)
>
>what i want is something like this:
>
>(SETF NewOBJECT (change-class-special SomeOBJECT SomeFurtherObject 'class4))h

(defun change-class-special (original-object other-object new-class)
  (let ((new-object (change-class original-object new-class)))
    (copy-other-slots new-object other-object)))

Then write appropriate COPY-OTHER-SLOTS methods.

>2.
>The second problem is using DEFMETHOD with Multiple objects
>eg
>(DEFMETHOD some-special-process ((obj1 class1) (obj2 class2))
>	......)
>(DEFMETHOD some-special-process ((obj1 class1) (obj2 class4))
>        ......)

I think you left something out of this part: your problem/question.
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

······@think.com          {uunet,harvard}!think!barmar