Defining Methods

Methods are defined using the call:

         (defmethod selector (args) code)

where selector is the name of the message, (args) is a list of the arguments of the method, and code is the Lisp code that implements the method.

A method is actually a special form of function definition. It looks almost like a function definition, except that (args) has a special form. Each argument may be either a variable name, or a list (variable class) to declare the class (type) of the variable.

An example method definition is:

(defmethod area ((self circle))
  (* pi (expt (sendm self 'radius) 2)) )

This becomes:

(defun circle-area (self)
  (* pi (expt (sendm self 'radius) 2)) )

Contents    Page-10    Prev    Next    Page+10    Index