I try to experiment with classes in LISP and I stuck at the following problem already at a very beginning level.
I define two classes "BIg" and "Small" so that "Small" is a subclass of "Big":
But then I execute the following code:
But by some reason attempts to create instances of the class "Small", e.g. calls
My question is: why "initialize-instance" chooses method for the class "Big" even when an instance of the class "Small" is created?
I define two classes "BIg" and "Small" so that "Small" is a subclass of "Big":
(defclass Big ()
( (my-value :accessor my-value)
))
(defclass Small (Big) () )
For the class "Small" I define an after-method of initialization:
(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:
(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
(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?
To understand LISP, you must first understand LISP.