From fbc8fe78c9f189870663694a21e35c7e56509fe1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 25 Sep 2026 08:46:53 +0200 Subject: [PATCH] Refuse a name registered as a builtin and a transform, build the offered calls once, and drop the done item --- template.go | 2 +- todo.md | 4 ---- transform.go | 9 ++++++--- value.go | 6 ++++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/template.go b/template.go index d23dd0b..7217f3f 100644 --- a/template.go +++ b/template.go @@ -120,8 +120,8 @@ type builtin struct { operands func(args []string) []string // number proves what a call prints, token its body: the bounds of its number and the // datatype of its text, prints or one inside it; nil for a builtin whose text is no number. - prints DataType number func(token string, prints DataType, args []string) proven + prints DataType } // funcCall splits a "{token}" body shaped name(args) into its parts; ok is false diff --git a/todo.md b/todo.md index 6abde67..ce749a6 100644 --- a/todo.md +++ b/todo.md @@ -19,10 +19,6 @@ Self-sufficiency 5.6), every seat capped by Locality or Self-sufficiency. This round, in order: -- Register a transform once: `transforms` restates the `lowercase`, `uppercase` and - `ascii` entries in `builtins`, and `valueProof.template` classifies by the first while - render calls the second. Derive the numeric builtins `valueProof.template` lists in - its error text from `builtin.number` while there. - Split `drawCheck.reads`'s six-term condition into named predicates. - Rename what names two things: `template.go` holds the token grammar while `template` is `node.go`'s type and `Template` `inline.go`'s; `kind` `'b'` is a brace body in diff --git a/transform.go b/transform.go index 0515889..f24be31 100644 --- a/transform.go +++ b/transform.go @@ -14,11 +14,14 @@ var transforms = map[string]func(string) string{ "uppercase": strings.ToUpper, } -func withTransforms(builtins map[string]builtin) map[string]builtin { +func withTransforms(calls map[string]builtin) map[string]builtin { for name, fn := range transforms { - builtins[name] = builtin{arity: 1, check: transformArg, prep: transformPrep(fn), operands: transformOperand} + if _, clash := calls[name]; clash { + panic("fejkdata: " + name + " is registered as a builtin and a transform") + } + calls[name] = builtin{arity: 1, check: transformArg, prep: transformPrep(fn), operands: transformOperand} } - return builtins + return calls } // unwrapTransform peels nested transform calls off an operand arg, returning the diff --git a/value.go b/value.go index d217fd0..94a1acf 100644 --- a/value.go +++ b/value.go @@ -149,8 +149,8 @@ func (p *valueProof) template(t *template) proven { case t.fixed: return literalValue(t.lit) case len(t.ops) != 1: - v := unproven(notOneValue(t.format, numberCalls(false))) - v.notOperand = notOneValue(t.format, numberCalls(true)) + v := unproven(notOneValue(t.format, typedCalls)) + v.notOperand = notOneValue(t.format, operandCalls) return v } o := t.ops[0] @@ -288,6 +288,8 @@ func printing(token string, prints DataType, v proven) proven { return v } +var typedCalls, operandCalls = numberCalls(false), numberCalls(true) + // numberCalls lists the builtins printing a number, or with text also those whose text // is one. func numberCalls(text bool) string {