Repository navigation
docs: literate-programming blocks, applied to /blocks - #116
Merged
Merged
Conversation
dangLiterateEval(sessionID, source) is dangReplEval with one display-rule difference: an entry whose last form is a declaration yields no value, only its printed output. It backs the docs' \dang-literate blocks, which bake their results into the page at build time (docs/go/literate.go) and replay client-side in one shared session — the two evaluators must agree on what a setup block shows, or the first Run would visibly rewrite outputs the reader already saw. evalForms now also reports whether the last form is a declaration, detected via DeclaredSymbols on the final node. Signed-off-by: Alex Suraci <[email protected]>
A \dang-literate block is a code fence that actually runs. All literate blocks in one source file share a single Dang environment, evaluated in document order at build time — later snippets can use earlier definitions, like cells of a notebook — and each block's output (stdout plus the value of its last form) is baked into the static page. A block that fails to parse, type-check, or evaluate fails the docs build, so literate examples can't rot the way the /blocks interpolation example did. Client-side, playground.js upgrades the blocks into the playground's overlay editor: Run (or Ctrl/Cmd+Enter) resets a shared wasm REPL session and replays the whole page top to bottom via dangLiterateEval, updating every output; editing a block dims its output and everything downstream until the next replay. Without JavaScript the baked outputs still show. Signed-off-by: Alex Suraci <[email protected]>
Reader feedback on /blocks: the `list.each { item, index => ... }` example
printed the literal text "${index}: ${item}" — interpolation only happens in
backtick templates, not double-quoted strings — and should be runnable.
Switch the string to a backtick template and convert the block-arguments and
optional-parameters fences to \dang-literate blocks, so they evaluate at
build time with their real output baked in (the broken example would have
failed the build). The snippets now define what they use: `list` and
`numbers` get bindings, and a `withArg` declaration joins the first fence so
the args-then-block call resolves. A short note up top tells readers the
examples share one environment and can be edited and replayed in the
browser.
Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
db9fede
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://beece72f.dang-3kk.pages.dev |
| Branch Preview URL: | https://literate-docs-plugin.dang-3kk.pages.dev |
Every claim on the page is now followed by a small \dang-literate block
demonstrating exactly that claim, all 23 sharing one environment evaluated
top to bottom by the docs build — fruits defined under "Block arguments" is
the list firstMatch searches four sections later. The bullet-reference prose
is reworked into sentences that each set up the evaluation after them.
The examples got better in the process: `{ _ + _ }` evaluating to doubles
shows "same one argument, not positional" more convincingly than prose;
nested `_` shadowing maps over a list of lists; `break x` from .each and
`continue 0` in .map show their yielded values; the Dagger-flavored
dot-block chain is replaced by a runnable string-method chain; and the null
sections actually evaluate a null receiver through `.{ }` (=> fallback) and
`.{{ }}` (=> null) side by side.
Two error cases stay prose, since a literate block that fails would fail the
build by design: the nested-function break target and expired escaped
blocks. The latter also can't be written runnably today — there is no
surface syntax for a function-type annotation, so a function can't return a
stored block reference.
All section headings and anchors ({#blocks}, {#implicit-param},
{#dot-block}) are unchanged, as are the Meta notes.
Signed-off-by: Alex Suraci <[email protected]>
The template left a newline between the result element and the closing tag
of .dang-literate-out. The container is white-space:pre-wrap, so that
newline rendered as a blank line after every baked output. Trim it with the
{{end -}} marker.
Signed-off-by: Alex Suraci <[email protected]>
A textarea defaults to two rows, and the autosize routine sets height from scrollHeight, which never drops below the rows-derived minimum — so every single-line literate block (and playground) rendered two lines tall once JS enhanced it. Set rows=1 like the REPL input already does, letting autosize grow from a one-line baseline. Signed-off-by: Alex Suraci <[email protected]>
|
@vito do you happen to have a public URL for docs yet? 🙏 I keep updating my bookmark with recent builds like https://edab6a36.dang-3kk.pages.dev/json-yaml, but it's a moving target, would be nice to have a non-changing link |
Editor textareas autosize by measuring scrollHeight, but the measurement is only valid for the width and font it was taken at: the content re-wraps when the viewport narrows (overflow:hidden then clips the extra lines) and again when the JetBrains Mono webfont swaps in. Register every editor's autosize in a shared list and re-run them all, frame-throttled, on window resize and document.fonts.ready. Signed-off-by: Alex Suraci <[email protected]>
Owner
Author
|
@gmile Yes! The docs are pushed to https://danglang.org whenever I merge into |
This was referenced Jun 12, 2026
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.
Docs feedback
— feedback on
/blocks, on thelist.each { item, index => print("${index}: ${item}") }example.The reader was more right than they knew (edit by "reader": oh, I knew): that example was broken, not just unidiomatic —
${...}only interpolates inside backtick templates, so it printed the literal text${index}: ${item}.The literate plugin
\dang-literate{{{ ... }}}is a code fence that actually runs:docs/go/literate.go): all literate blocks in one source file share a single Dang environment, evaluated in document order — later snippets use earlier definitions, like notebook cells. Each block's output (stdout + the value of its last form, suppressed when the last form is a declaration) is baked into the static HTML, so the page is complete without JS and a broken example fails the docs build. This bug couldn't have shipped through a literate block.playground.js): the blocks upgrade into the playground's overlay editor. Run (or Ctrl/Cmd+Enter) resets a shared wasm REPL session and replays the page top to bottom via a newdangLiterateEvalexport, updating every output; editing a block dims its output and everything downstream until the next replay./blocks rewritten in full literate style
The whole page is now alternating prose and evaluations: every claim is followed by a small literate block demonstrating exactly that claim — 23 blocks sharing one environment (
fruitsdefined under "Block arguments" is the listfirstMatchsearches four sections later). Highlights:.eachexample uses backticks and shows its real printed output{ _ + _ }⇒[2, 4, 6]demonstrates "every_is the same one argument" better than prose ever did; nested_shadowing maps over a list of listsbreak xfrom.eachandcontinue 0in.mapshow their yielded values.toUpper→.{ emphasize(_) }→.replace).{ }(⇒fallback) and.{{ }}(⇒null) side by sideTwo error cases stay prose since a failing literate block fails the build by design: the nested-function break target, and expired escaped blocks (which also can't be written runnably — there's no surface syntax for a function-type annotation, so a function can't return a stored block ref).
Section anchors (
{#blocks},{#implicit-param},{#dot-block}) and Meta notes are unchanged.🤖 Generated with Claude Code