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
lambdaspecial 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-methodspecial 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.
For example,(define-method add ((x <integer>) (y <rational>)) ...)
expands into(add-method add (make-method (list <integer> <rational>) (lambda (call-next-method x y) ...)))
Note that the list of specializers passed to
make-methodwill 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
define-methodspecial form, the free variable
call-next-methodis bound to a “call-next-method” procedure (see
make-chained-methodfor details). If the
define-methodbody refers to this variable, the defined method is a chained method, otherwise it is an ordinary method.