Repository navigation
Replace the for keyword with a loop builtin - #108
Merged
Merged
Conversation
Deploying dang with
|
| Latest commit: |
bcc7faf
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://71c2b155.dang-3kk.pages.dev |
| Branch Preview URL: | https://loop-not-for.dang-3kk.pages.dev |
Add loop, a global block-taking builtin that calls its block repeatedly
forever, exiting only via break (or return/raise) unwinding out of it. It
is the builtin equivalent of the infinite `for` form, continuing the
language's direction of moving repetition into the library alongside
.each/.map rather than dedicating a keyword to it.
The existing control-flow machinery handles everything generically: break
is caught at the call site, continue resolves at block-invocation level,
and mergeCallBreakTypes types the call result from the break values. The
declared return type is a bare type variable that only materializes
through break merging, so `loop { break 42 }` types as Int! — unlike the
`for` keyword, whose result is always nullable.
This paves the way for removing the `for` keyword, whose name promises
iteration the language intentionally routes through .each instead.
Signed-off-by: Alex Suraci <[email protected]>
Dang's `for` only ever looped on a condition — the name promised
iteration the language deliberately routes through .each — and the new
`loop` builtin covers everything it did, with better result typing.
Remove the keyword outright rather than deprecating: no production code
used it (only Dang's own tests), and Dang's semver is currently driven
entirely by Dagger's usage.
Conditional loops are now written with a mid-body guard, which the test
migrations show reads fine: `loop { if (!cond) { break } ... }`. The
LoopFrame control-frame kind goes away since block-call frames are the
only break/continue targets left, and condition-loop nullability rules
(and their error tests) are obsolete. A new error test pins what users
hit if they reach for the old keyword: `"for" not found`.
Also drop `for`/`in` from REPL keyword completion (`in` was never a
token), regenerate the tree-sitter grammar, and update the highlight
queries, VSCode grammar, docs, and language-reference skill to match.
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
A bare reference auto-calls, so referencing a function that requires a block argument is the same mistake as calling it without one — but it silently produced the function value instead, while the parenthesized call errored. The inconsistency surfaced when `dang fmt` rewrote the `loop()` error test to bare `loop` and the expected error vanished. Function references without calling are already spelled `&name`, so the bare form has no legitimate meaning. autoCallFnType now returns an error for block-taking function types, and every auto-call inference site propagates it. This also rescues the previously confusing goldens for the existing cases: `numbers.map` without a block now reports `function requires a block argument` instead of `cannot use (&block: (item: Int!, index: Int!): b): [b]! as [Int!]!`, and constructors/user functions match. Signed-off-by: Alex Suraci <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replaces the
forkeyword with aloopstdlib builtin, then removesforentirely.foronly ever looped on a condition — the name promised iteration that the language deliberately routes through.eachinstead. Rather than rename it towhile, this moves repetition into the library alongside.each/.map, where it always belonged:Why a builtin works for free
The existing control-flow machinery is fully generic:
breakis caught at the call site of any block-taking call,continueresolves at block-invocation level, andmergeCallBreakTypestypes the call result from the break values. The builtin's implementation is just an infinite Go loop calling the block — no new inference concepts, no parser special cases.The result typing actually improves over
for:loopdeclares a bare type variable that only materializes through break merging, soloop { break 42 }types directly asInt!, wherefor { break 42 }was forced nullable.Removal fallout
LoopFrameis gone — block-call frames are the only break/continue targets left.for (x != null) { ... }) is gone; the guard form (if (x == null) { break }) narrows identically via divergence."for" not foundat the call site (pinned by an error test).loop/guards; tree-sitter grammar regenerated; zed/nvim highlight queries (submodules pushed to their mains), VSCode grammar, REPL completions, docs, and the language-reference skill all updated. Also droppedinfrom REPL completions — it was never a grammar token.Technically a breaking change shipped without a major bump: nothing outside Dang's own tests used
for, and Dang's semver is currently driven entirely by Dagger's usage.Note: the zed extension's grammar submodule still pins an older dang commit that parses
for; the updated highlight query is compatible with both, so that bump can follow whenever.🤖 Generated with Claude Code