Let's say I write the following piece of code (please forgive any errors, I'm a Lisp newbie and I can't run CL on this machine)
(defclass o () ())
(defclass a (o) ())
(defclass b (o) ())
(defgeneric m (x))
(defmethod m ((x o))
(print "O")
)
(defmethod m ((x a))
(print "A")
(call-next-method (make-instance 'a))
)
(defmethod m ((x b))
(print "B")
(call-next-method (make-instance 'b))
)
(setq aa (make-instance 'a))
(m aa) ;prints A, then O
(setq bb (make-instance 'b))
(m bb) ;prints B, then O
According to my expectations, it should print what's written in the comments without any complaints.
What will happen if I add the following code?
(defclass c (a b) ())
(setq cc (make-instance 'c))
(m cc)
If I understand standard method combination, the applicable methods for cc
will be sorted as (m a)
, (m b)
, (m o)
, and (m b)
will not be called by call-next-method
successfully. But what will actually happen? Will CL complain when I define class c
and say that it invalidates the method chain for generic function m
? Or will there be a runtime error?