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
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
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-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-methodon specializers and the returned procedure.
#f, which means that the computed method declines to generate a method.
#tif object is a computed method, otherwise returns
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
Key is an arbitrary object that is used to identify the computed emp. The key is used by
delete-methodto decide whether two computed emps are the same; they are the same if their keys are
equal?. This is necessary because a generic procedure may have more than one computed emp with the same specializers.