(goops.info.gz) Basic Method Definition
Info Catalog
(goops.info.gz) Adding Methods to Generic Functions
(goops.info.gz) Method Definition Internals
Basic Method Definition
-----------------------
To add a method to a generic function, use the `define-method' form.
- syntax: define-method (generic parameter ...) . body
Define a method for the generic function or accessor GENERIC with
parameters PARAMETERs and body BODY.
GENERIC is a generic function. If GENERIC is a variable which is
not yet bound to a generic function object, the expansion of
`define-method' will include a call to `define-generic'. If
GENERIC is `(setter GENERIC-WITH-SETTER)', where
GENERIC-WITH-SETTER is a variable which is not yet bound to a
generic-with-setter object, the expansion will include a call to
`define-accessor'.
Each PARAMETER must be either a symbol or a two-element list
`(SYMBOL CLASS)'. The symbols refer to variables in the BODY that
will be bound to the parameters supplied by the caller when
calling this method. The CLASSes, if present, specify the
possible combinations of parameters to which this method can be
applied.
BODY is the body of the method definition.
`define-method' expressions look a little like normal Scheme procedure
definitions of the form
(define (name formals ...) . body)
The most important difference is that each formal parameter, apart from
the possible "rest" argument, can be qualified by a class name:
`FORMAL' becomes `(FORMAL CLASS)'. The meaning of this qualification
is that the method being defined will only be applicable in a
particular generic function invocation if the corresponding argument is
an instance of `CLASS' (or one of its subclasses). If more than one of
the formal parameters is qualified in this way, then the method will
only be applicable if each of the corresponding arguments is an
instance of its respective qualifying class.
Note that unqualified formal parameters act as though they are qualified
by the class `<top>', which GOOPS uses to mean the superclass of all
valid Scheme types, including both primitive types and GOOPS classes.
For example, if a generic function method is defined with PARAMETERs
`((s1 <square>) (n <number>))', that method is only applicable to
invocations of its generic function that have two parameters where the
first parameter is an instance of the `<square>' class and the second
parameter is a number.
If a generic function is invoked with a combination of parameters for
which there is no applicable method, GOOPS raises an error. For more
about invocation error handling, and generic function invocation in
general, see Invoking Generic Functions.
Info Catalog
(goops.info.gz) Adding Methods to Generic Functions
(goops.info.gz) Method Definition Internals
automatically generated byinfo2html