ce: for items, Python-spelled, in every builder - #114
Merged
Conversation
for target in source: runs its body once per element of a List or Seq with the target bound, inside seq/async/result/option (Python's for statement; a failed let! inside a result loop still short-circuits the block) and user builders (B.for_ e (fun x -> body), combined with what follows like a yield). for is a keyword only in item position inside CE braces; a body on the same line as the colon is exactly one item, a longer body goes on indented lines, and the pretty-printer lays such a block out on lines. return inside a loop body is rejected. Lesson 13 and 20, DESIGN §8.1, the internals table and ROADMAP item 15 updated.
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.
Closes #103 (the
foritem; the diagnostic and docs-table halves shipped in #112; custom operations are recorded as turned down in ROADMAP item 15).for target in source:in every builderThe Python spelling, consistent with
match e:/case.foris a keyword only in item position inside CE braces (Pyfun has no loop statement elsewhere). The source is aList aor aSeq a(an unresolved source is taken to be aList), the target any irrefutable pattern (for (a, b) in pairs:unpacks in the Python header), and the body is a nested level of the same block: anything butreturn, which is rejected with a message saying the block's value comes after the loop.seqlowers to Python'sforstatement, the idiomatic generator thatyield! (List.map f xs)was standing in for.asyncloops with awaits inside theasync def.result/option: a failedlet!inside the loop short-circuits the whole block; the items after the loop follow theforstatement.For:B.for_ e (fun x -> body), combined with what follows like ayield. The issue'sHtml { }DSL now writesfor r in rows: yield tr r.One layout rule
Braces carry no layout tokens, so the body is delimited by columns like every other item, with one Python-shaped rule: a body that begins on the same line as the
:is exactly one item (for x in xs: yield x), and a longer body goes on indented lines. The pretty-printer keeps one-line CEs one-line and lays a block out on lines only when aforbody has several items, soparse ∘ printstays idempotent (roundtrip tests added for both shapes, including nested loops). Inside CE bracesforalso stops an application, soyield a for c in cs: yield cis two items.Elsewhere
CeItem::Foris walked by the capture census, the fold pass's free-variable and binder collectors, the active-pattern arity scan, and the LSP resolver (the target is a nested scope, so go-to-definition and rename see it).DESIGN.md§8.1 gets the row and a paragraph; the internals table, lesson 13 (aforsection inseq) and lesson 20 (for_in the protocol) are updated; ROADMAP item 15 is closed.Tests
Typecheck (every builder, the
Seq stringelement type of a tuple target,return-in-loop and non-collection-source rejections), roundtrip (one-line and multi-line shapes), a parser unit test for the near-miss diagnostic, and one e2e program running all four builders.cargo test,cargo clippy --all-targets,cargo fmt --checkanddocs/verify_lessons.pyare clean.