Repository navigation
dang: dot-block application, .{{ }} selection, and implicit _ - #101
Merged
Merged
Conversation
Deploying dang with
|
| Latest commit: |
12e902c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6edc54d0.dang-3kk.pages.dev |
| Branch Preview URL: | https://piping-operator-design.dang-3kk.pages.dev |
A block with no explicit parameters that references `_` now takes a
single implicit parameter named `_`, Kotlin `it`-style: every `_` in
the block refers to the same single argument, so `{ _ * 2 }` and
`{ _ + _ }` both bind one value. This is detected in BlockArg.Infer,
which gives the block one implicit param (using the expected param type
when available) and binds it in the inference scope; eval then binds the
incoming value to `_` via the inferred parameter record.
Detection respects nesting: a reference inside a nested param-less block
belongs to that inner block, which shadows the outer `_`. Blocks with
explicit params do not capture `_`, so a `_` inside them resolves
outward. A bare `_` outside any block remains an undefined reference.
Signed-off-by: Alex Suraci <[email protected]>
Object selection now opens and closes on double braces, mirroring record
literals (`{{ }}`) — both already infer to the same anonymous structural
type, so the notation now reflects that identity. This frees the single
`.{ }` form for dot-block application in a following change.
The grammar change is confined to the ObjectSelection rule; inline
fragment field groups (`... on T { ... }`) keep their single braces.
Nested selections recurse through ObjectSelection, so they pick up the
double braces too. The formatter emits `{{ }}` to match, and all
existing selection sites across tests, mod, and demos are migrated.
Signed-off-by: Alex Suraci <[email protected]>
`receiver.{ block }` now calls the block with the receiver as its single
argument, so `foo.{ bar(_) }` and `foo.{ x => bar(x) }` both mean
`bar(foo)`. Combined with the implicit `_` parameter, this is the
language's piping primitive: a block, applied with a dot. Because it
sits at `.`'s precedence as a sibling of selection and method calls in
SelectOrCall, dot-block interleaves with real method calls in a single
chain.
A new DotApply node infers the receiver type, passes it as the block's
single parameter (the block must take 0 or 1 params; 2+ is a clear
error), and yields the block's body type. Unlike selection, dot-block
does not short-circuit on null: the receiver is bound even when null and
the block decides what to do. Selection still wins the `.{{` form via
ordered choice, and a space (`.{ {{...}} }`) lets a dot-block return a
record literal unambiguously. The formatter emits the receiver followed
by the block.
Signed-off-by: Alex Suraci <[email protected]>
The tree-sitter grammar is derived from the PEG, so regenerating picks up the selection move to double braces and the dot-block alternative in SelectOrCall. Regenerated grammar.json, node-types.json, and parser.c; the corpus tests still pass. Signed-off-by: Alex Suraci <[email protected]>
Updates the language docs for the selection/dot-block realignment.
Selection examples move to double braces (inline-fragment field groups
keep their single braces). blocks.md gains sections for the implicit `_`
parameter and for dot-block application as Dang's piping primitive,
including the chain-interleaving example. operators.md notes the two
postfix `.`-brace forms at `.` precedence, and grammar.md describes the
ObjectSelection and DotBlock productions.
The null-semantics divergence is called out where both appear: `.{{ }}`
selection short-circuits on null while `.{ }` dot-block binds the
receiver (even null) and lets the block decide.
Signed-off-by: Alex Suraci <[email protected]>
Exercises dot-blocks interleaved with a real method call in a single chain, mirroring the design discussion's Cargo module example, to guard the headline interleaving behavior end to end. Signed-off-by: Alex Suraci <[email protected]>
Reframes the null section so it follows from what dot-block is — block application, not navigation — rather than reading as a gotcha versus selection. A null receiver is simply passed into the block (`bar(null)`), which is what lets a block handle null; selection navigates fields and so short-circuits. Same `.`-brace surface, different jobs. Signed-off-by: Alex Suraci <[email protected]>
Dang has no `?.` optional-chaining operator, so the example was not valid syntax. The null-coalesce and explicit-null-check examples already show how a block handles null; remove the bogus one. Signed-off-by: Alex Suraci <[email protected]>
Regenerated docs/js/tree-sitter-dang.wasm from the rebased grammar via
the pinned dagger toolchain so the playground highlighter matches the
`.{{ }}` / `.{ }` grammar.
Signed-off-by: Alex Suraci <[email protected]>
vito
force-pushed
the
piping-operator-design
branch
from
June 9, 2026 14:13
3dd52fa to
12e902c
Compare
vito
added a commit
that referenced
this pull request
Jun 10, 2026
PR #101 changed `.{ }` from object selection to dot-block application, which breaks Dang code written before the merge. v1.0.0 was tagged from release/v1 with that change reverted so existing modules have a stable line to pin; main keeps the new syntax and becomes v2. Bump the module path to github.com/vito/dang/v2 so the breaking change requires an explicit opt-in from dependents, per Go's semantic import versioning. The docs module keeps its own github.com/vito/dang/docs path, with its require/replace of the root module updated to /v2. Install instructions in the docs now reference the /v2 path. Signed-off-by: Alex Suraci <[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.
Collapses the "pipe operator" question into primitives Dang already has, by realigning three things around the
.-brace surface. There's no|>, no word operator, and no new bracket — piping is just "a block, applied with.".What changed
1.
_implicit block parameter (Kotlinit-style). A block with no explicit parameters that references_gets a single implicit parameter_. Every_in the block refers to that same one argument, so{ _ * 2 }and{ _ + _ }both bind one value (not Scala positional params). It works everywhere blocks are used (xs.map { _ * 2 },xs.filter { _ > 0 })._binds to the nearest enclosing param-less block; a nested param-less block shadows it, and a block with explicit params doesn't capture it. A bare_outside any block stays an undefined-reference error.2. Object selection moved from
.{ }to.{{ }}, mirroring record literals. This surfaces an identity already true in the implementation: selection and record literals both infer to the same anonymous structural type (NewType("", ObjectKind)). Single-field.fieldis unchanged; only multi-field selects pay the extra brace. Inline-fragment field groups keep their single braces (pets.{{ ... on Cat { name } }}).3.
.{ }now means dot-block application.receiver.{ block }calls the block with the receiver as its single argument, sofoo.{ bar(_) }≡bar(foo)andfoo.{ x => bar(x) }≡bar(foo). Because it sits at.'s precedence as a sibling of selection and method calls inSelectOrCall, dot-block interleaves with real method calls in a single chain:The block must take 0 or 1 parameters (2+ is a clear error). None of the three introduces a new type-system concept — they reuse the existing block machinery and the selection/record-literal type identity.
Null semantics (the one gotcha)
.{{ }}and.{ }share the.-brace surface but diverge on null:.{{ }}selection short-circuits: a null receiver propagates null and the result type is nullable..{ }dot-block does NOT short-circuit: it binds the receiver (even null) to the parameter and runs the block, letting the block decide.This is documented prominently in
blocks.mdandgraphql.md.Migration
All ~95 existing selection sites across
tests/anddemos/were migrated to.{{ }}via a brace-matching codemod.mod/doug/main.dangwas intentionally left on single-brace syntax — it's Dang code executed by the dagger engine's pinned dang SDK (engineVersion v0.20.1), which predates{{; it can migrate once the engine bumps to a release including this change..daggerhas no selections and is unaffected.Verification
dagger checkis fully green: docs, lint, go tests (992 passed / 0 failed), tree-sitter corpus, and the generate freshness check. Newassert-based tests cover the implicit_(map/filter/each,{ _ + _ }single-binding, nested shadowing, explicit-param blocks, bare-_error), dot-block application (implicit/explicit params, null receiver, multi-param rejection, chaining, the.{ {{...}} }adjacency case), and a Cargo-style interleaving smoke test.Notes / follow-ups
_-highlighting in the nvim/zed tree-sitter queries (separate submodule repos) was not added; highlight-compatibility tests pass as-is and_is an ordinary identifier in the grammar.🤖 Generated with Claude Code