Chapter 5

Types and Classes

Limited Types

Limited types are subtypes of classes constrained by additional criteria. Limited types are created with the function limited. limited(<integer>, min: 0, max: 255) and limited(<array>, of: <single-float>) are examples of limited types that are useful both for error checking and for optimization of compiled code.

Limited types are not classes.

Errata: In the published book, a comma is missing between 0 and max:.

Limited Type Constructor

Limited types are created with the generic function limited. The first argument to limited is a class. Depending on the class, additional keyword arguments are allowed to specify the constraints of the limited type.

Not all classes support limited; the methods for limited are documented individually beginning on page 263.

Limited Integer Types

Limited integer types are subtypes of <integer> containing integers that fall within a specifed range. The range is specified by min: and max: keyword arguments to limited.

For example:

// accepts integers between -1000 and 1000 inclusive.
define method f (x :: limited(<integer>, min: -1000,
                                         max: 1000))
  end method f;

//accepts all strictly positive integers.
define method f (x :: limited(<integer>, min: 1))
  end method f;

Limited Integer Type Protocol

If w, x, y, and z are integers, the following equivalences hold:

Limited Collection Types

Limited collection types are subtypes of <collection> (and of subclasses of <collection>) that are constrained to be a specified size and/or to contain elements of a specified type.

A complete description of limited collection types is given in Limited Collection Types on page 126 in Chapter 8, Collections.