Combining Two Dissimlar Classes Slots

Discussion of Common Lisp

Combining Two Dissimlar Classes Slots

Postby 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!
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Combining Two Dissimlar Classes Slots

Postby 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.
User avatar
Kohath
 
Posts: 50
Joined: Mon Jul 07, 2008 8:06 pm
Location: Toowoomba, Queensland, Australia

Re: Combining Two Dissimlar Classes Slots

Postby Harnon » Tue Sep 15, 2009 7:45 am

Thanks1 Thats exactly what i was looking for :)
Harnon
 
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Combining Two Dissimlar Classes Slots

Postby 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:
User avatar
Kohath
 
Posts: 50
Joined: Mon Jul 07, 2008 8:06 pm
Location: Toowoomba, Queensland, Australia


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 2 guests