Skip to content

Make every example in the dynamics API reference compile - #606

Merged
godofecht merged 2 commits into
mainfrom
docs-dynamics-imports
Aug 19, 2026
Merged

godofecht merged 2 commits into
mainfrom
docs-dynamics-imports

Conversation

@godofecht

@godofecht godofecht commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

docs/library/dynamics.md had eight unverified blocks and now has none. unverified: 220 -> 212.

Why they failed

The imports were in the prose, not the fence. Each section says:

import "stdlib/dynamics/linalg.flow"

above the block rather than inside it, so no block could be copied and run. They are in the blocks now.

Buffers appeared from nowhere. The Matrix values pointed at a_buf, b_buf, c_buf, and the Gramian, GA and closed-loop calls passed scratch arrays that were never declared. Those are declared now, sized from the actual signatures in lib/stdlib/dynamics/, each with a line saying what it is for:

# Scratch: the Gramian itself plus three n x n workspaces.
let mut wb: array<f64, 4> = [0.0, 0.0, 0.0, 0.0]

A reader copying any of these now gets a program rather than a fragment.

Twelve lines of setup would have been repeated four times. The blocks that build on the system constructed earlier say uses=system instead.

Two fixes to uses=, found by its first real use

This is the first page to use the mechanism from #584 in anger, and it exposed two things.

Context belongs inside the harness. I had put it in the preamble, above the block. A chapter's earlier block is usually statements, so let sys = dsys_discrete(...) landed at module scope where the parser requires let mut. Every one of these blocks failed with an error about the harness rather than the example.

Imports hoist when context is joined. A block naming context also imports its own module, so joining them naively left an import in the middle, after the context's statements, and every harness rung read it as an expression:

SyntaxError: Unexpected token in expression: TokenType.IMPORT

Both are covered by new tests, including one asserting a repeated import is joined once.

Verification

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

@godofecht
godofecht force-pushed the docs-dynamics-imports branch from e055c59 to 82cb7c8 Compare August 19, 2026 23:10
godofecht and others added 2 commits August 20, 2026 00:14
docs/library/dynamics.md had eight unverified blocks and now has none.

Each section stated its import in prose, above the fence rather than in it,
so no block could be copied and run. The imports are in the blocks now.

Two blocks referenced buffers that were never declared: the Matrix values
pointed at a_buf, b_buf and c_buf, and the Gramian, GA and closed-loop calls
passed scratch arrays out of nowhere. Those are declared, sized from the
signatures in lib/stdlib/dynamics/, with a line saying what each is for. A
reader copying any of these now gets a program.

The four blocks that build on the system built earlier on the page say so
with uses=, rather than repeating twelve lines of setup each time.

Two fixes to the uses= mechanism, both found by this being its first real
use:

Page context now joins the block's own code rather than the preamble, so the
harness wraps both together. Above it, `let sys = dsys_discrete(...)` landed
at module scope, where the parser requires `let mut`, and every one of these
blocks failed for a reason unrelated to the example.

Imports hoist when context is joined. A block naming context also imports its
own module, so joining them left an `import` after the context's statements
and every harness rung read it as an expression.

unverified: 220 -> 212.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@godofecht
godofecht force-pushed the docs-dynamics-imports branch from 82cb7c8 to 2923f63 Compare August 19, 2026 23:15
@godofecht
godofecht merged commit 0dae7cf into main Aug 19, 2026
21 checks passed
@godofecht
godofecht deleted the docs-dynamics-imports branch August 19, 2026 23:28
godofecht added a commit that referenced this pull request Aug 20, 2026
PR #606 already made the detailed dynamics reference compile without deleting its API signatures and examples. Preserve that focused cleanup instead of the older broad rewrite.
godofecht added a commit that referenced this pull request Sep 7, 2026
PR #606 already made the detailed dynamics reference compile without deleting its API signatures and examples. Preserve that focused cleanup instead of the older broad rewrite.
godofecht added a commit that referenced this pull request Sep 7, 2026
PR #606 already made the detailed dynamics reference compile without deleting its API signatures and examples. Preserve that focused cleanup instead of the older broad rewrite.
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