[Next] [Previous] [Up] [Top] [Contents] [Index]

8 Collections

Limited Collection Types

Limited collections are subtypes of <collection> which are constrained to have a particular size or dimensions and which are constrained to hold elements of a particular type.

If C is a subclass of <collection> whose element type is indefinite < T1, then it is possible to create any number of limited collection types which can be described as limited(C, of: T2, size: S).

Like a collection class, a limited collection type has a conceptual element type. The element type of limited(C, of: T2, size: S) is T2. T2 must be an instance of <type> and a subtype of T1. C is the base class of the new limited collection type.

S limits the size of instances of a limited collection type. S can be #f, which means no limitation, or a non-negative integer, which means that every instance of the limited collection type has exactly that many elements.

S must be #f if C is stretchy (e.g. <table>, <stretchy-vector>, or <deque>).

If C is <array> then it is also possible to create any number of limited collection types which can be described as limited(<array>, of: T, dimensions: D). D must be a sequence of non-negative integers; the rank of each instance is size(D) and the dimensions of each instance are the elements of D. You cannot specify both size: and dimensions: in the same type.

Some limited collection types are instantiable. make(limited(C, ...), ...) returns a direct instance of some subclass of C. Typically this class is not standardized and its name is not exported, but it is valid for this class to be C itself. There is nothing special about this class; it is simply a class known to the applicable limited method and its creation is subject to all the usual sealing restrictions.

An object X is an instance of a limited collection type limited(C, of: T2, size: S) if and only if all of the following are true:

Element Type Subclassing

The element-type subclassing rules are generalized to limited collection types as follows (this is implied by the preceding and is included here for explanatory purposes only):

If the element type of a limited collection type L1 is T1, each instance of L1 stores elements of type T1. The element method will always return an instance of T1 and the element-setter method will accept any instance of T1. Each limited collection type that is a subtype of L1 must have an element type T2 that is equivalent to T1.

If the element type of a class C1 is indefinite < T1, each limited collection type that is a subtype of C1 has an element type T2 and T2 must be a subtype of T1. Thus element on any instance of C1 will return an instance of T1 (and will not return all possible instances of T1 if T2 is a proper subtype of T1), and it is not determined by C1 what the applicable element-setter method will accept (hence the term "indefinite").

The above statements about the value returned by element only apply when no default: keyword argument is specified.

Creating Limited Collection Types

You obtain a type object for a limited collection type by calling the limited generic function on a collection class. There are several built-in methods for limited specialized for specific subclasses of <collection>. Each of these methods accepts a required keyword argument of: and also accepts an optional keyword argument size: if the class is not stretchy. If the class is <array> the optional keyword argument dimensions: is also accepted. Each method returns a type. The returned type is never a class. If the size: keyword argument is accepted but not supplied, it defaults to #f.

Users cannot write portable methods for limited. There are no built-in methods for limited applicable to user-defined classes.

Uninstantiable Limited Collection Types

Methods on limited support the creation of uninstantiable limited types for the following classes:

Instantiable Limited Collection Types

Methods on limited support the creation of instantiable limited types for the following classes:


Dylan Reference Manual - 17 OCT 1995
[Next] [Previous] [Up] [Top] [Contents] [Index]

Generated with Harlequin WebMaker