9.3.5 Method dispatch and limited collections
When a type is a limited-collection type, Dylan uses the following rules:
1. An object is an instance of a limited-collection type if all the following are true: the class of the object is a subclass of the base type; the two element types are equivalent; and, if the limited-collection type restricts the size or dimensions, the size or dimensions of the object are the same as those specified for the type. If the object is an instance of <strectchy-collection>, the limited-collection type cannot restrict the size or dimensions.
2. A limited-collection type is a proper subtype of its base type, as long as it is not equivalent to the base type.
Generally, one limited-collection type is a proper subtype of another limited-collection type if all the following are true: the base type of the first is a subclass of the base type of the second; the two element types are equivalent; the size or dimensions of the first limited type are no less restricted than those of the second type; and the first limited type is not equivalent to the second.
For example, suppose that we have these definitions:
define constant <limited-vector-of-3-integers> = limited(<vector>, of: <integer>, size: 3); define constant <limited-vector-of-3-numbers> = limited(<vector>, of: <number>, size: 3); define constant $v1 = make(<limited-vector-of-3-integers>, size: 3, fill: 1); define constant $v2 = vector(1, 1, 1); // Method 1 define method say (x :: <vector>) ... end method say; // Method 2 define method say (x :: <limited-vector-of-3-integers>) ... end method say; // Method 3 define method say (x :: <limited-vector-of-3-numbers>) ... end method say;
Now, if say is called with an argument of $v1, both method 1 and method 2 are applicable, and method 2 is more specific than method 1. Note that $v1 is an instance of <limited-vector-of-3-integers> but is not an instance of <limited-vector-of-3-numbers>, because the element type of $v1 is not equivalent to the element type of <limited-vector-of-3-numbers>.
If say is called with an argument of $v2, only method 1 is applicable. Note that $v2 is not an instance of either of the limited-collection types we defined, even though $v2 is a vector that contains three integers. (For example, we could store objects other than integers in $v2.)




