5 Types and Classes
limited
. limited(<integer> ,min: 0 max: 255)
and limited(<array>, of: <single-float>)
are examples of limited types which are useful both for error checking and for optimization of compiled code.Limited types are not classes.
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 on page 249.
<integer>
containing integers which 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.
end method f;
define method f (x :: limited(<integer>, min: -1000,
max: 1000))
...
//accepts all strictly positive integers.
...
define method f (x :: limited(<integer>, min: 1))
end method f;
instance?(x limited(<integer>, min: y max: z))
will be true if and only if instance?(x, <integer>)
, (y <= x)
, and (x <= z)
are all true.
instance?(x, limited(<integer>, min: y))
will be true if and only if instance?(x, <integer>)
and (y <= x)
are both true.
instance?(x, limited(<integer>, max: z))
will be true if and only if instance?(x, <integer>)
and (x <= z)
are both true.
subtype?(limited(<integer>, min: w, max: x),
limited(<integer>, min: y, max: z))
will be true if and only if (w >= y)
and (x <= z)
are both true.
subtype?(limited(<integer>, min: w ...),
limited(<integer>, min: y ...))
will be true if and only if (w >= y)
is true.
subtype?(limited(<integer>,... max: x),
limited(<integer>,... max: z))
will be true if and only if (x <= z)
is true.
<collection>
(and of subclasses of <collection>
) which may be constrained to be a specified size and to contain elements of a specified type.A complete description of limited collection types is given in "Limited Collection Types" on page 124 in Chapter 8, "Collections."
Generated with Harlequin WebMaker