Sunday, October 14

Change-class extensibility

I made an interesting minor discovery today: change-class is extensible in much the way
initialize-instance is...

CL-USER> (defclass test-class () ((a-slot :initarg :a-slot-value :initform 0)))
CL-USER> (defclass derived-class (test-class) ())
CL-USER> (defmethod update-instance-for-different-class :after ((old test-class) (new derived-class) &key fixup-information)
(format t "~A " fixup-information))
CL-USER> (make-instance 'test-class :a-slot-value 27)
CL-USER> (defparameter *test-instance* (make-instance 'test-class :a-slot-value 27))
CL-USER> (change-class *test-instance* 'derived-class :fixup-information "Hello World")
Hello World

I'm not sure I actually want to use this, but it's nice to know it's there..

No comments: