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 values 1, 2, 3, 4 and 5.
  • `a` ... `z` returns the lower-case letters between a and z.

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 values 1, 2, 3 and 4.
  • `0` ..< `9` returns the digits 0 through to 8.

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 numbers 0 to 9. The n-th member is the number n.

Additional Remarks

  • The range operators '...' and '..<' are borrowed from the Swift programming language.