8.16.0.2
A range, or an interval, represents a contiguous
set of integers between two points. When the starting point is
included, the range can be used as a sequence; in addition,
when the ending point is not #inf, the range is
listable. Generally, the starting point must be less than or
equal to the ending point, so that the lower bound is “less than or
equal to” the upper bound by comparison on bounds.
A range supports membership tests using the in
operator, which is the same as Range.contains.
The
Range annotation matches any range.
The SequenceRange annotation matches a range that
can be used as a sequence, for which
Range.includes_start returns true.
The ListRange annotation matches a range that is
listable, for which Range.includes_start returns
true, and Range.end returns non-#inf.
Static information associated by SequenceRange or
ListRange makes an expression acceptable as a
sequence to for in static mode.
When start_expr .. end_expr or start_expr .. is
used in an each clause of for, the
optimization is more aggressive in that no intermediate range is
created.
When start_expr ..= end_expr is used in an
each clause of for, the optimization
is more aggressive in that no intermediate range is created.
Constructs a range that includes start, but does not
include end. The corresponding binding matches the
constructed range.
Constructs a range that includes both start and
end. The corresponding binding matches the constructed
range.
Constructs a range that includes start, and with
#inf as the ending point. The corresponding binding matches
the constructed range.
Constructs a range that does not include either start or
end. Unlike the other constructors, start must be
less than (but not equal to) end, otherwise the
lower bound would be “greater than” the upper bound. The
corresponding binding matches the constructed range.
Constructs a range that does not include start, but
includes end. The corresponding binding matches the
constructed range.
Constructs a range that does not include start, and with
#inf as the ending point. The corresponding binding matches
the constructed range.
Constructs a range with #neginf as the starting point, and
does not include end. The corresponding binding matches the
constructed range.
Constructs a range with #neginf as the starting point, and
includes end. The corresponding binding matches the
constructed range.
Constructs a range with #neginf as the starting point and
#inf as the ending point. The corresponding binding matches
the constructed range.
Returns the starting point and ending point of rge,
respectively. The starting point can be #neginf, and the
ending point can be #inf, indicating the lack of a starting
point or ending point.
Returns #true if rge includes the starting point
and the ending point, respectively, #false otherwise. A
#neginf starting point or #inf ending point
cannot be included.
Returns
#true if
rge is an
empty range,
#false otherwise. An empty range is empty
“by definition,” meaning that its lower bound is “equal to” its
upper bound, and therefore it cannot have anything at all in the
range that it represents. By contrast, a range may have no integers
even if its lower bound is strictly “less than” its upper bound
(but it may well have real numbers, in principle); in such case, use
rge.canonicalize().is_empty() to check for its
“emptiness.”
|
#false |
|
#false |
|
#true |
|
#true |
|
#false |
> (3 <.. 4).canonicalize().is_empty() |
|
#true |
Returns the canonical form of rge with respect to the
discrete domain of integers. The canonical form has and only has all
integers that rge has, and is guaranteed to be in one of
the following forms:
Furthermore, if rge is already in canonical form, it is
returned as-is.
|
1 .. 5 |
|
1 .. |
|
.. 5 |
|
.. |
|
1 .. 6 |
|
.. 6 |
> (1 <.. 5).canonicalize() |
|
2 .. 5 |
|
2 .. |
> (1 <..= 5).canonicalize() |
|
2 .. 6 |
Checks whether
rge has
int in the range that it
represents. See also
in.
Checks whether the given ranges are in enclosing order. A range
rge encloses another range rge2 when
rge has every integer in rge2. Every
range encloses itself, and empty ranges never enclose non-empty
ranges.
|
#true |
|
#true |
|
#true |
|
#false |
|
#false |
|
#true |
Checks whether rge is connected with rge2, that
is, whether there exists a range (possibly empty) that is enclosed by
both rge and rge2.
Checks whether rge overlaps with rge2, that is,
whether there exists a non-empty range that is enclosed by both
rge and rge2.
Returns the smallest range that encloses rgs and all
rges.
Returns the largest range that lies between rge and
rge2, or #false if no such range exists
(precisely when rge overlaps with rge2).
|
5 <.. 8 |
|
4 .. 6 |
|
8 .. 8 |
|
#false |
Returns the intersection of the given ranges, or #false
if no such range exists. The intersection of a range
rge and another range rge2 is the
largest range that is enclosed by both rge and
rge2, which only exists when rge is
connected with rge2.
|
.. |
|
2 ..= 8 |
|
4 <..= 8 |
|
4 <.. 6 |
|
2 <..= 5 |
|
#false |
Implements
Listable by returning a
list of
integers in
rge in order.
Implements
Sequenceable by returning a
sequence of integers in
rge in order. The sequence
is infinite when the ending point is
#inf.
Returns a
sequence of integers in
rge in order,
stepping by the given
step size.
When invoked as rge.step_by(step) in an
each clause of for, the sequence is
optimized, in addition to the optimization in .. or
..=.