Ranges - Spicery/Nutmeg GitHub Wiki
Closed Ranges
Closed ranges are written A ... B
, where A and B expressions, and return all the ordered values between A and B inclusively. They can be used on numbers and characters. e.g.
1 ... 5
returns the values1
,2
,3
,4
and5
.`a` ... `z`
returns the lower-case letters betweena
andz
.
Half-Open Ranges
Half-open ranges are very similar to closed-ranges except that they exclude the final value. For example:
1 ..< 5
returns the values1
,2
,3
and4
.`0` ..< `9`
returns the digits0
through to8
.
Combined with List Syntax
Ranges enclosed inside list brackets are guaranteed to be optimised into RangeLists, which are lists whose contents are procedurally calculated rather than explicitly managed. This guarantee is made so that we do not need a separate syntax for literal range-lists.
Examples:
[ 0 ..< 10 ]
is a RangeList whose members are the numbers0
to9
. The n-th member is the numbern
.
Additional Remarks
- The range operators '...' and '..<' are borrowed from the Swift programming language.