(goops.info.gz) Basic Generic Function Creation
Info Catalog
(goops.info.gz) Creating Generic Functions
(goops.info.gz) Generic Function Internals
Basic Generic Function Creation
-------------------------------
The following forms may be used to bind a variable to a generic
function. Depending on that variable's pre-existing value, the generic
function may be created empty - with no methods - or it may contain
methods that are inferred from the pre-existing value.
It is not, in general, necessary to use `define-generic' or
`define-accessor' before defining methods for the generic function
using `define-method', since `define-method' will automatically
interpolate a `define-generic' call, or upgrade an existing generic to
an accessor, if that is implied by the `define-method' call. Note in
particular that, if the specified variable already has a _generic
function_ value, `define-generic' and `define-accessor' will _discard_
it! Obviously it is application-dependent whether this is desirable or
not.
If, for example, you wanted to extend `+' for a class representing a
new numerical type, you probably want to inherit any existing methods
for `+' and so should not use `define-generic'. If, on the other hand,
you do not want to risk inheriting methods whose behaviour might
surprise you, you can use `define-generic' or `define-accessor' to wipe
the slate clean.
- syntax: define-generic symbol
Create a generic function with name SYMBOL and bind it to the
variable SYMBOL.
If the variable SYMBOL was previously bound to a Scheme procedure
(or procedure-with-setter), the old procedure (and setter) is
incorporated into the new generic function as its default
procedure (and setter). Any other previous value that was bound
to SYMBOL, including an existing generic function, is overwritten
by the new generic function.
- syntax: define-accessor symbol
Create an accessor with name SYMBOL and bind it to the variable
SYMBOL.
If the variable SYMBOL was previously bound to a Scheme procedure
(or procedure-with-setter), the old procedure (and setter) is
incorporated into the new accessor as its default procedure (and
setter). Any other previous value that was bound to SYMBOL,
including an existing generic function or accessor, is overwritten
by the new definition.
Info Catalog
(goops.info.gz) Creating Generic Functions
(goops.info.gz) Generic Function Internals
automatically generated byinfo2html