Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Subslice

The subslice postfix operation indexes a range of a slice value, returning a new slice spanning that range. The start index is inclusive; the end index is exclusive.

Process

At runtime:

  1. the operand is evaluated;
  2. the start index expression is evaluated;
  3. the end index expression is evaluated; and
  4. the slice of the operand's elements from the start index, inclusive, up to the end index, exclusive, is the subslice's result.

For a start or end index outside the slice's range, or a start index greater than the end index, is a runtime error; the compiler emits runtime logic to detect it, unless it can be proven that the indices are within range and the start index does not exceed the end index. A negative index value is always out of range.

See the runtime error model on the architecture page.

Assertions

  1. The operand's type is a slice type.
  2. Each index expression has an integer type, signed or unsigned.
  3. The subslice has the operand's slice type.

Syntax

subslice_operation = left_bracket, expression, comma, expression, right_bracket ;