Combining Two Dissimlar Classes Slots

Discussion of Common Lisp
Post Reply
Harnon
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Combining Two Dissimlar Classes Slots

Post by Harnon » Mon Sep 14, 2009 4:14 pm

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!

Kohath
Posts: 61
Joined: Mon Jul 07, 2008 8:06 pm
Location: Toowoomba, Queensland, Australia
Contact:

Re: Combining Two Dissimlar Classes Slots

Post by Kohath » Mon Sep 14, 2009 7:48 pm

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.

Harnon
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Combining Two Dissimlar Classes Slots

Post by Harnon » Tue Sep 15, 2009 7:45 am

Thanks1 Thats exactly what i was looking for :)

Kohath
Posts: 61
Joined: Mon Jul 07, 2008 8:06 pm
Location: Toowoomba, Queensland, Australia
Contact:

Re: Combining Two Dissimlar Classes Slots

Post by Kohath » Tue Sep 15, 2009 4:26 pm

My pleasure :). It's nice to be able to help out - and I'm gradually getting more proficient with Lisp.......... :mrgreen:

Post Reply