I define two classes "BIg" and "Small" so that "Small" is a subclass of "Big":
- Code: Select all
(defclass Big ()
( (my-value :accessor my-value)
))
(defclass Small (Big) () )
For the class "Small" I define an after-method of initialization:
- Code: Select all
(defmethod initialize-instance :after ( (item Small) &key )
(setf (my-value item) 13)
)
At this stage there is no problem with creating instances of both classes.
But then I execute the following code:
- Code: Select all
(defgeneric Func (item) )
(defmethod initialize-instance :after ( (item Big) &key )
(setf (my-value item) (Func 666) )
)
Clearly, there are no methods defined for a new generic function Func and an attempt to create an instance of the class "Big" leads to errors.
But by some reason attempts to create instances of the class "Small", e.g. calls
- Code: Select all
(setf x (make-instance 'Small ) )
also give the same error message saying that (Func 666) cannot be computed!
My question is: why "initialize-instance" chooses method for the class "Big" even when an instance of the class "Small" is created?