Skip to content

Collections: list comprehensions #63

@MelbourneDeveloper

Description

@MelbourneDeveloper

Scope

Implements Phase 6 of docs/plans/collections.md.

Lower [expr for x in source if guard] to a stream-fused chain over source's iterator, written into a transient builder, sealed at the end.

Required work

  1. Grammar additions for the comprehension syntax (LSQUARE expression FOR ID IN expression (IF expression)? RSQUARE).
  2. make regenerate-parser.
  3. AST node for ListComprehension.
  4. Builder + codegen lowering that emits an iterator chain → transient builder → seal.
  5. Tested examples in compiler/examples/tested/basics/lists/.

Acceptance

  • [x*x for x in range(start: 1, end: 6)] evaluates to [1, 4, 9, 16, 25].
  • The if guard form lowers to a filter stage.
  • make ci green.

Origin

docs/plans/collections.md Phase 6 (deferred — grammar work pending Phase 5 patterns landing first, to avoid two grammar revisions in flight).

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