5.5 Operating upon classes
Selecting the Metaclass option selects, and describes in the normal way, the class of the current class.
The Find Definition option searches for the definition of the current class, in all of the Common Lisp so far interpreted from files. If it is found, the file is made available for inspection in the Editor. The cursor is placed at the start of the definition.
Note: You can find only the definitions of your own classes (that is, those for which you have written source code), not those provided by FreeLisp.
The Direct Generic Functions, Inherited Generic Functions, Direct Methods, and Inherited Methods options all invoke the function viewer. This is a window which lists generic functions and methods which discriminate upon the current class. See Figure 5.11, page 71.
Figure 5.11 The function viewer.
In order to demonstrate these options at work, we have to define some methods upon our classes. Consider the example below.
CL-USER 6 > (defmethod feed ((arg dog)) 'woof-woof) #<STANDARD-METHOD FEED NIL (DOG) 004707E4> CL-USER 7 > (setq fido (make-instance 'dog)) #<DOG 004A8544> CL-USER 8 > (feed fido) WOOF-WOOF CL-USER 9 >In this example, a method
feed
is defined for dogs, which declares that any dog you feed will express its approval with a "woof-woof". The dog fido
is fed and behaves appropriately. Below, the method pet
is defined upon animals. This method returns an animal's response to being patted. As we do not know the specific characteristics of a general animal, we can only express that it will respond to being patted in some way:
CL-USER 9 > (defmethod pat ((arg animal)) 'respond) #<STANDARD-METHOD PAT NIL (ANIMAL) 004B4C5C> CL-USER 10 > (pat fido) RESPOND CL-USER 11 >Note that
fido
responds because, as a dog, it is also an animal: dogs inherit methods defined upon animals since animal
is a superclass of dog
. Now that we have methods both inherited by and defined directly upon dogs, we can view them, and the generic functions associated with them, in the function viewer.
1. Examine the dog
class in the class browser by typing dog into the name area.
2. Select Class > Direct Generic Functions in the class browser.
The function viewer lists the direct generic functions which discriminate upon dogs.
Figure 5.12 Direct generic functions discriminating upon dogs.
3. Select Class > Inherited Generic Functions in the class browser.
The function viewer lists the inherited generic functions which discriminate upon dogs.
Figure 5.13 Inherited generic functions discriminating upon dogs.
4. Select Direct Methods and Inherited Methods in turn.
The function viewer lists the method feed
, and then pat
and other system-related methods which are inherited by dog
.
Generated with Harlequin WebMaker