Previous: Chained Methods, Up: Methods
A computed method is a powerful mechanism that provides the ability to generate methods “on the fly”. A computed method is like an ordinary method, except that its procedure is called during method combination, and is passed the classes of the arguments in place of the arguments themselves. Based on these classes, the computed method returns an ordinary method, which is combined in the usual way.
Note that computed methods and computed emps both satisfy the
predicate method?
. They are not really methods in that they
cannot be combined with other methods to form an effective method
procedure; however, they are treated as methods by procedures such as
add-method
and method-specializers
.
Create and return a computed method. Procedure will be called during method combination with the classes of the generic-procedure arguments as its arguments. It must return one of the following:
- An ordinary method (as returned by
make-method
ormake-chained-method
). The returned method's specializers must be restrictions of specializers, i.e. each specializer in the returned method must be a subclass of the corresponding specializer in specializers. In the usual case, the returned method's specializers are the same as specializers.- A procedure, which is converted into an ordinary method by calling
make-method
on specializers and the returned procedure.#f
, which means that the computed method declines to generate a method.
Returns
#t
if object is a computed method, otherwise returns#f
.
A computed emp takes the computed-method mechanism one step
further. A computed emp is like a computed method, except that it
returns an effective method procedure rather than a method.
compute-effective-method-procedure
tries each of the applicable
computed emps, and if exactly one of them returns an emp, that
is the resulting effective method procedure.
Create and return a computed emp. Procedure will be called during method combination with the classes of the generic-procedure arguments as its arguments. It must return either an emp or
#f
.Key is an arbitrary object that is used to identify the computed emp. The key is used by
add-method
anddelete-method
to decide whether two computed emps are the same; they are the same if their keys areequal?
. This is necessary because a generic procedure may have more than one computed emp with the same specializers.