(rontolisp) docs
← Macros

change-class

(change-class instance 'class-name initarg value ...)

Changes the class of an existing instance in place and returns it: the object keeps its identity (every other reference sees the change), the slots the old and the new class share keep their values, the slots the new class adds are filled from their :initforms, and any supplied initargs are stored on top. The class argument is a class designator: a literal quoted name, a runtime symbol, or a class metaobject — (change-class obj (find-class 'c)) works, as does a class name held in a variable. #'change-class (through funcall or apply) takes the same designators and initargs.

Slots match by name (CLHS 7.2), also between classes of unrelated inheritance chains; an added slot without :initform starts unbound. When a shared-initialize method applies to the new class, the added slots start unbound and shared-initialize runs with their names and the initargs, as the system method of update-instance-for-different-class does; a method on update-instance-for-different-class itself is never called.