Page 1 of 1

Combining Two Dissimlar Classes Slots

Posted: Mon Sep 14, 2009 4:14 pm
by Harnon
I know this is possible, but i can't find how to do it!
Say i have
(deflcass aa ((name :initarg :name)))
(defclass bb ((name :initarg :name) (c :initarg :c)))

Then , if i have an instance of class aa, i would like to create an instance of bb with all similar slots which bb has in common with aa filled in from aa.
Is this possible? I think there is some inbuilt way to do this, but i'm not sure.
Thanks!

Re: Combining Two Dissimlar Classes Slots

Posted: Mon Sep 14, 2009 7:48 pm
by Kohath
It jogged my memory, and I found change-class. HTH

Code: Select all

(defclass aa () ((name :initarg :name :accessor name)))
(defclass bb () ((name :initarg :name :accessor name) (c :initarg :c)))
(defparameter ana (make-instance 'aa :name :jimmy))
(change-class ana 'bb)
ana
(name ana)
Notice that name still has the given value, and the instance prints out as belonging to the BB class.

Re: Combining Two Dissimlar Classes Slots

Posted: Tue Sep 15, 2009 7:45 am
by Harnon
Thanks1 Thats exactly what i was looking for :)

Re: Combining Two Dissimlar Classes Slots

Posted: Tue Sep 15, 2009 4:26 pm
by Kohath
My pleasure :). It's nice to be able to help out - and I'm gradually getting more proficient with Lisp.......... :mrgreen: