This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Combining Two Dissimlar Classes Slots

4 posts · 1525 views

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

It jogged my memory, and I found change-class. HTH
(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.
blog.metalight.net

Re: Combining Two Dissimlar Classes Slots

Thanks1 Thats exactly what i was looking for :)

Re: Combining Two Dissimlar Classes Slots

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