### 5.4 Computed 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`.

Procedure: make-computed-method specializers procedure

  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` or `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-method` on specializers and the returned procedure.
  - `#f`, which means that the computed method declines to generate a method.

Procedure: computed-method? object

  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.

Procedure: make-computed-emp key specializers 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` and `delete-method` to 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.

Procedure: computed-emp? object

  Returns `#t` if object is a computed EMP, otherwise returns `#f`.

Generic Procedure: computed-emp-key computed-emp

  Returns the key for computed-emp.