Repository navigation
Every Solve It the Flow Way example runs in the browser - #617
Merged
Merged
Conversation
Two of the five ran. The other three needed features the browser interpreter did not have, and the gallery teaches idioms, so a reader pressing Run on one and being told to go and install a compiler is the wrong answer. Restored first: the effects work from #581 was written but not merged. The merge took the gallery and the wiki publishing and left site/flow-compile.js and site/wiki.js behind, so effect declarations, capabilities, handle blocks and Effect.op dispatch were absent from main. Recovered from the dangling commit rather than rewritten. Then three features: Pipeline forks. `n |> Stats { doubled = twice, plus_ten = add(_, 10) }` runs each named function over the piped value and collects the results. The `_` placeholder logic already existed for ordinary stages and is now shared. Enums and choose. `enum Mode { Double, Triple }` becomes a struct holding a tag plus one constant per variant, which is what the native compiler lowers it to, so `Mode { tag: Mode_Double }` and `m.tag` mean the same thing in both. `|> choose m.tag { Mode_Double => double }` selects which function the value flows through. Flow blocks. `flow Thermostat { state ... param ... solver ... evolves as ... every 100 ms { ... } }` lowers to a struct plus Name_new, Name_default_dt and Name_step, so the existing struct, pointer and call machinery runs it instead of a second evaluator living beside the first. Explicit Euler; a method that is not euler says which one it was asked for. Checked against the native compiler rather than against a tolerance. 20000 steps of the thermostat with its every-block firing 200 times prints temp=20.414 heater=1.0 from both. Top-level constants were parsed and never installed as globals, so every reference to one was an undefined variable. Enum variants are constants, which is how that surfaced. verify_browser_interp.py: 240 snippets, unsupported 13 -> 12, no new disagreement. 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.
Two of the five ran. The gallery teaches idioms, so a reader pressing Run and being told to go install a compiler is the wrong answer.
Each program returns 1 on a failed assertion, so exit 0 is the program checking itself rather than merely reaching the end.
First, something that had been lost
The effects work from #581 was written but not merged. That merge took the gallery and the wiki publishing and left
site/flow-compile.jsandsite/wiki.jsbehind, so effect declarations, capabilities,handleblocks andEffect.opdispatch were absent from main. Recovered from the dangling commit rather than rewritten.Three features
Pipeline forks.
n |> Stats { doubled = twice, plus_ten = add(_, 10) }runs each named function over the piped value and collects the results. The_placeholder logic already existed for ordinary stages and is now shared between the two.Enums and
choose.enum Mode { Double, Triple }becomes a struct holding a tag plus one constant per variant, which is exactly what the native compiler lowers it to, soMode { tag: Mode_Double }andm.tagmean the same thing in both.|> choose m.tag { Mode_Double => double }selects which function the value flows through.Flow blocks.
flow Thermostat { state … param … solver … evolves as … every 100 ms { … } }lowers to a struct plusName_new,Name_default_dtandName_step. That reuses the existing struct, pointer and call machinery rather than putting a second evaluator beside the first. Explicit Euler only; a method that is noteulersays which one it was asked for.Checked against the native compiler, not a tolerance
20000 Euler steps with the every-block firing 200 times:
A stepper that is close is not the same as one that agrees.
A bug this surfaced
Top-level
constnever worked.prog.constswas written by the parser and read by nothing, so every reference to a constant was an undefined variable. Enum variants are constants, which is how it came to light. Fixed generally, not just for enums.Verification
verify_browser_interp.pypipelines-3was already failing on main)pytest tests/Nine tests in
tests/unit/test_browser_interpreter_gallery.py, including a guard that fails if the gallery grows past the five programs it asserts about. They read the gallery throughdocs_blocks.iter_blocksrather than a regex, since a regex over fences mispairs a closing fence with the next opening one.