From fd7101dfbc2a25c49680d85d4c7b1bc22bdf29b1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 5 Oct 2026 23:13:05 +0200 Subject: [PATCH] Answer prose round 1: readName and readField say one idea a sentence and name what each pick and read is, and the test's message names whose b it checks --- pick.go | 11 ++++++----- pick_test.go | 2 +- render.go | 11 ++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pick.go b/pick.go index c0f7178..c4cb498 100644 --- a/pick.go +++ b/pick.go @@ -141,11 +141,12 @@ func (sc renderScope) frameOf(scope *nameScope) *pickFrame { return nil } -// readName reads a from its name's pick in the frame rendering the name's scope. A read entering -// another category takes the frames of the name scopes there from the pick's memo (enter), and -// renderFrame finds them and opens none, so every read of the pick reads one pick of each name -// bound there: {a.street} and {a.postal-code} in data/sv_SE/address.json read one pick of the -// name l that data/geo/SE/address.json binds. +// readName reads the arm a from the pick of its name, held in the frame of the name's scope. +// When the pick renders another category, enter takes that category's frames from the pick's +// memo, and renderFrame finds them and opens no new one. +// So every read through one pick sees one pick of each name the other category binds: +// {a.street} and {a.postal-code} in data/sv_SE/address.json read one pick of the name l +// that data/geo/SE/address.json binds. func readName(s *drawstate.State, sc renderScope, a arm) readValue { f := sc.frameOf(a.named.scope) if f == nil { diff --git a/pick_test.go b/pick_test.go index 157abc8..52f40cc 100644 --- a/pick_test.go +++ b/pick_test.go @@ -340,7 +340,7 @@ func TestAFreshReadInsideANamedPickSharesNoValueWithIt(t *testing.T) { for i := 0; i < 100; i++ { got := mustRender(t, f, src) if m := want.FindStringSubmatch(got); m == nil || m[1] != m[2] { - t.Fatalf("draw %d = %q, want p.a's c drawn afresh and its b read from p's pick", i, got) + t.Fatalf("draw %d = %q, want c's b from x, y or z, and p.a's b equal to {p.a.b}", i, got) } } } diff --git a/render.go b/render.go index 55aac74..f4858f0 100644 --- a/render.go +++ b/render.go @@ -142,11 +142,12 @@ func expand(s *drawstate.State, t *template, sc renderScope) string { return b.String() } -// readField renders one arm of a token. A read of a name, or of a level a read of the name -// rendering addresses, is kept in that name's pick; every other read draws afresh, so {word} -// {word} draws twice and {p.a} {p.b} reads two draws of p. A fresh read leaves the pick: a read -// below it would key the pick's memo by sc.pickKey, the level the pick rendered, so it and the -// pick would read one value for two nodes. +// readField renders one arm of a token. A read is kept in a name's pick when it reads the name, or +// a level that a read of the name being rendered addresses; every other read draws afresh, so +// {word} {word} draws twice and {p.a} {p.b} reads two draws of p. +// A fresh read clears sc.pick. Kept, a read nested in the fresh one would key the pick's memo by +// sc.pickKey, the path from the name to what the pick renders, and share a value with a different +// node at that path. func readField(s *drawstate.State, t *template, sc renderScope, a arm) readValue { switch { case a.kind == namedRead: