8000 feat(control): bounded iteration in the strict core — recursion-with-cursor is unreviewable · Issue #267 · Mnehmos/mnehmos.nls.lang · GitHub
[go: up one dir, main page]

Skip to content

feat(control): bounded iteration in the strict core — recursion-with-cursor is unreviewable #267

Open

Description

@Mnehmos

@-

Activity

  1. added
    enhancementNew feature or request
    coreCore language semantics and design
    specificationLanguage specification documents
    on Sep 13, 2026
  2. Mnehmos commented on Sep 13, 2026

    @Mnehmos
    OwnerAuthor

    Implemented in #269 (fix/issue-264-scaffold-containment).

    Syntax shipped (per the note on #263 — authoring form now, revisable when the surface decision lands):

    FOR EACH <var> IN <list> [WHERE <cond>]: ADD <expr>     -> <binding>
    FOR EACH <var> IN <list> [WHERE <cond>]: COLLECT <expr> -> <binding>
    

    ADD accumulates from 0, COLLECT appends from []. Design constraints from the issue all held: bounded only (no WHILE in the core), explicit accumulator named in the step, both targets.

    Both targets, via the IR. It lowers to a checked IRForEach node, so the type checker, effect/failure analysis and both emitters consume one structure. The capability gate now distinguishes a fold from an effect-only FOR each loop step, so folds are no longer refused on TypeScript. Scoping is enforced: the loop variable is scoped to the step (reading it afterwards is ESEM004), the target binding is visible after.

    Corpus effect — the walkers are gone. Strict-clean examples 5/8 → 7/8:

    example before after
    sorting, sorting_ja, sorting_ts 3 comprehensions each folds; all strict-clean
    billing [line-items-total] cursor walker deleted, one fold
    showcase [science-total], [payload-total], [sampling-hours] — 7 lines each one step each

    Japanese surface included: <list> の 各 <var> について [もし <cond>]: 合計|収集 <expr>.

    Two latent TypeScript bugs surfaced and fixed. Once the sorting examples stopped being scaffolds they took the IR path for the first time, which exposed: return-type inference only recognised comprehensions as list producers (a COLLECT binding inferred number instead of number[]), and the IR path rendered list concatenation as JS +, which stringifies arrays. Both now covered by cross-target tests that execute quicksort on Node and compare against the Python artifact — worth noting these were reachable before this change by any IR-path module returning a concatenated list.

    Not covered: the pairwise walkers [route-distance] and [build-legs] stay recursive. They carry the previous element across iterations, which a fold cannot express without tuples. A SCAN-shaped construct would fold them too; not proposed here.

    21 new tests; suite 1219 passing.

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

    coreCore language semantics and designenhancementNew feature or requestpriority-highImportant, address soonspecificationLanguage specification documents

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0