9.3 Method dispatch and nonclass types

In this section, we describe the implications for method dispatch of using nonclass types as parameter specializers. This advanced topic is included as reference material; you can skip it safely if you prefer. The description that we give here is meant to provide a general understanding, and does not cover all cases. For exact details, you should consult The Dylan Reference Manual.

Recall that, when a generic function is called, Dylan determines which method to invoke by comparing the required arguments passed to the generic function with the types of the corresponding parameters of the generic function's methods. Dylan uses the following procedure, assuming that there is only one required argument:

1. Find all the applicable methods. A method is applicable if the required argument is an instance of the type of the specialized parameter.

2. Sort the applicable methods in order of specificity. One method is more specific than another if the type of its specialized parameter is a proper subtype of the type of the other method's specialized parameter. For definitions of "proper subtype" in various situations, see Sections 9.3.1 through 9.3.5.

(In the presence of multiple inheritance, the specificity rule is more complex. For more information, see Section 18.4, page 300.)

3. Call the most specific method.

(If there is more than one required argument, Dylan constructs the sorted list of methods by combining separate sorted lists for all required arguments.)

For any given argument and any given set of parameter types, Dylan has to answer two questions:

1. Is the argument an instance of a given type? The answer determines method applicability.

2. Is one type a proper subtype of another type? The answer determines method specificity.