Skip to content

Add range literals and indexed for sugar #37

@synapticvoid

Description

@synapticvoid

Summary

Add range iteration and indexed loop sugar to improve loop ergonomics.

Proposed Syntax

for i in 0..10 {}
for i in 0..10 by 2 {}
for elem, i in list {}

Semantics

  • a..b is end-exclusive
  • by sets step (default 1)
  • for elem, i in list is indexed sugar over list + range index generation

Scope

  • Parser/type-checker/runtime support for range literals and by
  • Indexed loop sugar lowering/expansion rules
  • Validation for invalid zero step and incompatible bounds/step types

Out of Scope

  • Infinite ranges (0..)
  • Reverse/descending shorthand beyond explicit negative step
  • Multi-iterable zip (tracked separately)

Acceptance Criteria

  • for i in 0..5 {} iterates 0,1,2,3,4
  • for i in 0..10 by 2 {} iterates 0,2,4,6,8
  • for elem, i in list {} binds element and index correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions