Skip to content

CEP-0014: Custom Ranges and Step Semantics

Draft

Draft proposal for user-defined range domains and step/successor semantics. V1 range expressions are limited to the accepted integer-oriented expression, slicing, and iteration model.

Summary

Catalyst should eventually decide whether range syntax can support non-integer domains and custom step semantics.

V1 keeps ranges simple: range expressions are values used by slicing and iteration, and collection behavior is shaped through explicit contracts.

Example

Possible future shape:

const start = Beat { bar: 1, beat: 1 }
const stop = Beat { bar: 4, beat: 1 }

for beat in start..stop step Beat.quarter {
  schedule(beat)
}

The proposal must define successor, step, termination, and endpoint rules for non-integer domains.

Motivation

Custom ranges can be useful for domains such as time, musical positions, Unicode ranges, geometric grids, or user-defined index spaces. They are also easy to make ambiguous if successor, endpoint inclusion, and iteration behavior are implicit.

The range model should stay explicit enough for loop lowering, slicing, diagnostics, and performance reasoning.

Proposed Direction

The future design should cover:

  • user-defined/custom ranges for non-integer domains;
  • successor and step semantics;
  • inclusive and exclusive endpoint behavior;
  • range iteration contracts or helper APIs;
  • whether range patterns in pattern matching reuse the same model;
  • diagnostics for empty, invalid, or non-terminating custom ranges.

V1 Compatibility

V1 range syntax remains limited to the accepted expression and slicing model. Unchecked indexing is tracked separately by CEP-0024.