Skip to content

docs: preamble= for running examples, and three more Book fixes - #553

Merged
godofecht merged 2 commits into
mainfrom
docs/book-and-effects-examples
Aug 18, 2026
Merged

godofecht merged 2 commits into
mainfrom
docs/book-and-effects-examples

Conversation

@godofecht

@godofecht godofecht commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

The problem preamble= solves

Chapter 5 declares struct Sample once in 5.1 and then uses it in six later blocks. All six were failing. Repeating the struct in each would bury what the block is actually showing:

let t: i32 = first.time_ms
let measurement: f64 = first.value

preamble=<path> names a file whose declarations precede the block when it compiles. The prose has already shown the reader the struct, so the checker sees it too.

Two details that needed getting right:

The preamble sits outside the harness. My first attempt prepended it to the block and then wrapped the whole thing, which for a statement block nested a struct inside a synthesized main. Chapter 5 went from 5 verified to 5 verified and looked fine until I read the errors. There is a test pinning this.

A missing preamble file is a failure, not a silent skip, so the tag cannot rot into a no-op.

This key was removed from the info string in an earlier PR precisely because it did nothing. It is back now that it does something.

Its limit, recorded rather than papered over

A preamble supplies declarations, not locals. Module statics must be primitives, fixed arrays of primitives, or ptr<T>:

Module static 'first' has unsupported type 'Sample': module statics must be a
primitive (i32/i64/u8/u32/f32/f64/c64/c128/bool), a fixed array of primitives,
or ptr<T>

So a chapter's running let first: Sample = ... cannot live in one. I tried, it made things worse (8 verified back down to 5), and I reverted it. Three blocks in chapter 5 need local context and stay in the ledger. A statement-level preamble would be a second mechanism; it did not seem worth inventing for three blocks.

Three Book examples that relied on an earlier block

Chapter Needed Now
04-functions 4.3 clamp, written in 4.2 carries it
05-records mean4 Sample, from 5.1 via preamble
08-types trait/impl Point — the page never declared it anywhere declares it

The third is the interesting one: chapter 8 writes a trait Comparable and an impl ... for Point against a type that appears nowhere on the page.

Count

before   verified 430   unverified 255
after    verified 436   unverified 249

Chapter 5 goes from 6 unverified to 3.

Validation

  • Unit suite 1498 passed, 2 skipped (3 new, on preamble placement, resolution and the missing-file case)
  • check_doc_links.py and check_doc_coverage.py clean
  • ruff check src clean
  • Ledger refreshed

godofecht and others added 2 commits August 18, 2026 16:38
Chapter 5 declares `struct Sample` once in 5.1 and then uses it in six later
blocks. Every one of those was failing, and repeating the struct six times
would bury what each block is showing.

`preamble=<path>` names a file whose declarations precede the block when it
compiles. The prose has already shown the reader the struct, so the checker
sees it too. The preamble sits outside the harness, since wrapping it inside
a synthesized main would nest a struct in a function body; there is a test
for that specifically. A missing preamble file is a failure rather than a
silent skip.

The key was removed from the info string in an earlier PR precisely because
it did nothing. It is back now that it does something.

Its limit is worth recording: a preamble supplies declarations, not locals.
Module statics have to be primitives, fixed arrays of primitives, or ptr<T>,
so a chapter's running `let first: Sample = ...` cannot live in one. Three
blocks in chapter 5 need that and stay in the ledger.

Three Book examples also relied on definitions from an earlier block on the
same page and now carry them:

  - 04-functions 4.3 calls clamp, written in 4.2
  - 05-records mean4 reads samples[i].value, with Sample from 5.1
  - 08-types declares a trait and impl over Point, which the page never
    declared at all

Examples: verified 430 to 436, unverified 255 to 249.

Unit 1498 passed, links and coverage clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@godofecht
godofecht merged commit e09fd59 into main Aug 18, 2026
19 checks passed
@godofecht
godofecht deleted the docs/book-and-effects-examples branch August 18, 2026 19:08
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