Answer architecture round 2: guard Noun's range, name calc once as builtinfunc.Calc, and place readTableOptions in item 46
This commit is contained in:
@@ -43,6 +43,10 @@ type builtin struct {
|
||||
prints datatype.DataType
|
||||
}
|
||||
|
||||
// Calc is the name of the builtin whose operands the caller checks and proves, as nodes only
|
||||
// it holds.
|
||||
const Calc = "calc"
|
||||
|
||||
// rng is the randomness a builtin sample draws from, which *drawstate.State satisfies.
|
||||
type rng interface {
|
||||
IntN(n int) int
|
||||
|
||||
@@ -66,7 +66,7 @@ var builtins = withTransforms(map[string]builtin{
|
||||
}},
|
||||
"date": {arity: -1, checkArgs: dateArgs, prep: datePrep},
|
||||
"time": {arity: -1, checkArgs: timeArg, prep: timePrep},
|
||||
"calc": {arity: -1, checkArgs: checkCalc, prep: calcPrep, operands: calcOperands, noRefOperands: true},
|
||||
Calc: {arity: -1, checkArgs: checkCalc, prep: calcPrep, operands: calcOperands, noRefOperands: true},
|
||||
// seq is the one stateful builtin: a per-generator counter from 1, advancing on
|
||||
// each call. An optional name selects an independent counter; no name uses the
|
||||
// default one. Deterministic by construction, so seeded output stays stable.
|
||||
|
||||
@@ -31,4 +31,9 @@ func (d DataType) String() string {
|
||||
}
|
||||
|
||||
// Noun is the datatype as an error names what a value is.
|
||||
func Noun(d DataType) string { return nouns[d] }
|
||||
func Noun(d DataType) string {
|
||||
if d < 0 || d >= Count {
|
||||
return d.String()
|
||||
}
|
||||
return nouns[d]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user