Methods
say that is called only on alisa, an instance of fourth-grader, then specify child to be eql to alisa, as shown in the following example. The expression (declare (ignore sentence)) avoids a compiler warning. The function call-next-method calls the next most specific method, which is the method on fourth-grader:
? (defmethod say ((child (eql alisa)) sentence)
(declare (ignore sentence))
(call-next-method)
(princ "I have an HP calculator")
(terpri))
#<Method SAY ((EQL #<FOURTH-GRADER #x436B51> T)>
? (say alisa "Hello")
***Hello!***
I have an HP calculator
NILApplied to other fourth-graders, such as sharon, say still calls its usual fourth-grader method.
? (say sharon "Hello")
***Hello!***
NIL
* Note: The function call-next-method is perfectly acceptable here, but CLOS more commonly would use an :after method. Method combination is discussed later in "Creating auxiliary methods and using method qualifiers" on page 100.
Generated with Harlequin WebMaker