Repository navigation
docs: preamble= for running examples, and three more Book fixes - #553
Merged
Merged
Conversation
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]>
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.
The problem preamble= solves
Chapter 5 declares
struct Sampleonce 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: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
structinside a synthesizedmain. 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>: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
clamp, written in 4.2mean4Sample, from 5.1Point— the page never declared it anywhereThe third is the interesting one: chapter 8 writes a
trait Comparableand animpl ... for Pointagainst a type that appears nowhere on the page.Count
Chapter 5 goes from 6 unverified to 3.
Validation
check_doc_links.pyandcheck_doc_coverage.pycleanruff check srcclean