6.37 Ranges
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.
rge.start()
is
Range.start(rge)
rge.end()
is
Range.end(rge)
rge.includes_start()
is
Range.includes_start(rge)
rge.includes_end()
is
Range.includes_end(rge)
rge.has_element(int)
is
Range.has_element(rge, int)
is
Range.encloses(rge, rge2, ...)
rge.is_connected(rge2)
is
Range.is_connected(rge, rge2)
rge.overlaps(rge2)
is
Range.overlaps(rge, rge2)
is
Range.span(rge, rge2, ...)
rge.gap(rge2)
is
Range.gap(rge, rge2)
is
Range.intersect(rge, rge2, ...)
rge.to_sequence()
is
Range.to_sequence(rge)
rge.step_by(step)
is
Range.step_by(rge, step)
rge.to_list()
is
Range.to_list(rge)
annotation |
|
annotation |
|
annotation |
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.
expression |
|
binding operator |
|
expression |
|
binding operator |
|
expression |
|
binding operator |
|
expression |
|
binding operator |
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.
expression |
|
binding operator |
|
expression |
|
binding operator |
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.
expression |
|
binding operator |
|
expression |
|
binding operator |
expression |
|
binding operator |
function |
|
binding operator |
function | ||
| ||
binding operator | ||
function |
fun Range.from(start :: Int) :: SequenceRange |
|
binding operator |
function | ||
| ||
binding operator | ||
function | |||
| |||
binding operator | |||
function |
|
binding operator |
function |
|
binding operator |
function |
fun Range.full() :: Range |
|
binding operator |
function |
|
function |
function |
|
function |
#true
#true
#false
> Range.encloses()
#true
#true
#true
#false
#false
#true
#true
#true
#false
#true
#true
#false
2 ..= 5
2 .. 9
..= 6
.. 9
5 <..< 8
4 .. 6
8 .. 8
#false
> Range.intersect()
..
2 ..= 8
4 <..= 8
4 <..< 6
2 <..= 5
#false
function |
function | ||
|
When invoked as rge.step_by(step) in an each clause of for, the sequence is optimized, in addition to the optimization in .. or ..=.