Skip to content

[Medium] List comprehensions don't support multi-variable/C-style/nested for clauses #108

Description

@particlesector

Location: src/lang/Expr.h (ListCompExpr/ListCompBody), src/lang/Parser.cpp (comprehension parsing), src/lang/Interpreter.cpp (evaluation).

Real OpenSCAD's list-comprehension for clause supports:

  • multiple variables in one clause: [for (i=[0:2], j=[0:2]) i*3+j]
  • C-style for(init; cond; next): [for (i=0, x=1; i<5; i=i+1, x=x*2) x]
  • nested for clauses within one bracket: [for (i=a) for (j=b) i+j]

ListCompExpr/ListCompBody (Expr.h) are explicitly single-variable only today, so all three forms fail to parse. Note this is specifically about the expression form ([for (...) ...]) — the statement form (for () { ... }, CsgEvaluator's ForNode) already supports multi-variable clauses as of a prior fix (see closed issue #90's "for-nested-tests" work), which used a different AST path (ForClause list). This gap needs the equivalent treatment applied to ListCompBody.

Why this matters for real-world scripts: OpenSCAD has no mutable state, so C-style for is the idiomatic way to do accumulator-style math (running sums/products) inside a comprehension. Multi-variable comprehensions are a common pattern for generating grids/matrices. Both show up in intermediate-to-advanced .scad scripts and libraries, not just edge-case test files.

Originally noted as a deferred gap in docs/roadmap.md (now trimmed); filing as a tracked issue instead.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions