Skip to content
Giorgio Garofalo edited this page Oct 5, 2024 · 4 revisions

The syntax to define a range is a..b, with a and b non-negative integers, e.g. 2..10.

Both a and b might also be omitted - in that case the range becomes open.

According to the amount of delimiters provided, a range can be classified as:

  • Closed range: a..b
  • Open on the left end: ..b
  • Open on the right end: a..
  • Open on both ends: ..

The behavior of open ranges is not universally defined, but rather defined by each function that accepts a range.

 

For instance, the .read function accepts a range of lines to be read from the file, so 2..10 means only the lines from 2 to 10 (included) will be read.

  • If the range is open on the left end (..10) it starts reading from the beginning of the file until line 10.
  • If the range is open on the right end (2..) it reads from line 2 to the end of the file.
  • If the range is open on both ends (..) the whole file is read.

This strategy is common for slicing operations across the stdlib.

Clone this wiki locally