The following syntactic form greatly simplifies the definition of methods, and of adding them to generic procedures.
Defines a method of generic-procedure. Lambda-list is like
the parameter list of a
lambda special form, except that the
required parameters may have associated specializers. A parameter with
an associated specializer is written as a list of two elements: the
first element is the parameter’s name, and the second element is an
expression that evaluates to a class.
Lambda-list must contain at least one required parameter, and at least one required parameter must be specialized.
define-method special form expands into the following:
(add-method generic-procedure (make-method (list specializer …) (lambda (call-next-method . stripped-lambda-list) body …)))
where stripped-lambda-list is lambda-list with the
specialized parameters replaced by their names, and the
specializers are the corresponding expressions from the
specialized parameters. If necessary, the specializers are
interspersed with references to
<object> in order to make them
occur in the correct position in the sequence.
(define-method add ((x <integer>) (y <rational>)) ...)
(add-method add (make-method (list <integer> <rational>) (lambda (call-next-method x y) ...)))
Note that the list of specializers passed to
correspond to the required parameters of the method; the specializer
corresponding to a non-specialized required parameter is
Further note that, within the body of a
form, the free variable
call-next-method is bound to a
“call-next-method” procedure (see
details). If the
define-method body refers to this variable, the
defined method is a chained method, otherwise it is an ordinary method.