Skip to content

Make every example in the expressions and matching chapter compile - #622

Merged
godofecht merged 1 commit into
mainfrom
docs-book09-context
Aug 20, 2026
Merged

godofecht merged 1 commit into
mainfrom
docs-book09-context

Conversation

@godofecht

@godofecht godofecht commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

docs/book/09-expressions-and-matching.md had nine unverified blocks and now has none. unverified: 167 -> 159.

The chapter's shape decided the fix

It shows one form per block over bare stand-in names:

let magnitude: i32 = if n >= 0 { n } else { -n }

Repeating let n: i32 = 3 above each of those would bury the form the block exists to show. So the stand-ins live in a preamble fixture and the fragments stay one line each. That is precisely what preamble= is for: context that is deliberately not on the page, as against uses=, which is for context the page does show.

Two blocks could not use it

Module statics may not hold a struct or enum type (#562), so point and mode cannot be declared in a preamble. Those blocks declare their own subject instead, one line each:

let point: Point = Point { x: 0, y: 0 }

match point { ... }

Same for the array-pattern block, which matched on samples without one anywhere.

A block that could not have compiled in any context

The match-arms example returns strings from its arms:

match n {
    0 => { return "zero" }
    1 | 2 | 3 => { return "small" }
}

with no enclosing function, so the harness wrapped it in main and the return type disagreed. It only makes sense inside a function returning a string, and now says so: function describe(n: i32) -> string.

One catalogue

The ordering block lists forms over illustrative collections (values |> sort descending, players |> sortBy [desc .score, asc .name]) and now carries that as its reason.

Verification

Check Result
pytest tests/ 1735 passed, 6 skipped
check_doc_examples.py --check-ledger no new unverified, 167 → 159
check_doc_links.py all links and fragments resolve

docs/book/09-expressions-and-matching.md had nine unverified blocks and now
has none.

The chapter shows one form per block over bare stand-in names: `if n >= 0`,
`while active`, `match point`. Repeating a declaration above each would bury
the form the block exists to show, so the stand-ins live in a preamble
fixture and the fragments stay one line each. That is what preamble= is for:
context that is deliberately not on the page.

Two blocks could not use it. Module statics may not hold a struct or enum
type (#562), so `match point` and `choose mode.tag` declare their own subject
now, one line each. Same for the array-pattern block, which matched on
`samples` without one.

The match-arms block returns strings from its arms, which only makes sense
inside a function returning one. It said

    match n {
        0 => { return "zero" }
        ...
    }

with no enclosing function, so the harness wrapped it in `main` and the
return type disagreed. Now `function describe(n: i32) -> string`.

The ordering block is a catalogue of forms over illustrative collections
(`values |> sort descending`, `players |> sortBy [...]`) and says so.

unverified: 167 -> 159.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@godofecht
godofecht force-pushed the docs-book09-context branch from c204da9 to 79f8c2e Compare August 20, 2026 17:10
@godofecht
godofecht merged commit 4b4f4d8 into main Aug 20, 2026
21 checks passed
@godofecht
godofecht deleted the docs-book09-context branch August 20, 2026 17:29
godofecht added a commit that referenced this pull request Aug 20, 2026
Take the focused chapter 9 fixes from #622 and keep the audit branch's remaining documentation work on top.
godofecht added a commit that referenced this pull request Sep 7, 2026
Take the focused chapter 9 fixes from #622 and keep the audit branch's remaining documentation work on top.
godofecht added a commit that referenced this pull request Sep 7, 2026
Take the focused chapter 9 fixes from #622 and keep the audit branch's remaining documentation work on top.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant