Previous: , Up: Methods   [Contents][Index]


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:

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.


Previous: , Up: Methods   [Contents][Index]