template

package
v0.1.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package template fills the templates of tasks: it counts the instances of a template, runs its solver on them, builds each one with its numbers, and picks the instance of an attempt from the attempt's seed (format/README.md, sections 22–24; R60 spec, R61 spec). api calls it for the instance of an attempt, and the check of a module and the build of a package for every instance.

Instances checks a template by the rules of templates that it breaks by itself — task.template-names, task.template-expressions, task.placeholders, task.template-instances and task.template-solver — and counts its instances in the order of the odometer, each with its numbers: the expressions of the narrow subset of Starlark, read and typed here and evaluated in the sandbox of internal/sandbox (R32); and the results of its solver, a program of Starlark run once on a thread of its own, whose solve is called on every instance in turn with the numbers that Inputs names, within the budget of the template (R33). Instance puts the numbers of an instance in the place of the placeholders, in a single pass, with no expression and no Starlark, as api does with the numbers that the package carries; the open view of an instance is openview.Task of it. AttemptInstance picks the instance of an attempt by its number, from the place of randomness of the attempt's seed that the format gives a template, through internal/random (R31).

Index

Constants

View Source
const (
	RuleNames        = "task.template-names"
	RuleExpressions  = "task.template-expressions"
	RulePlaceholders = "task.placeholders"
	RuleInstances    = "task.template-instances"
	RuleSolver       = "task.template-solver"
)

The rules of templates that a template breaks by itself — by its names, its expressions, its placeholders, the combinations of its parameters and its solver — whatever its instances hold (format/README.md, sections 23 and 24). task.placeholders holds outside a template too, and the check of a module reads it there.

View Source
const MaxInstances = 10000

MaxInstances is the most instances a template has: the sizes of its domains multiply to at most 10 000 (format/README.md, section 23).

Variables

View Source
var ErrDomain = random.ErrDomain

ErrDomain is what AttemptInstance gives on an argument outside its domain: a count outside 1 to MaxInstances, or an ID that is no name of a place of randomness. It is the generator's own, so that errors.Is finds it whichever of the two gives it.

Functions

func AttemptInstance

func AttemptInstance(seed uint64, task formatv0.TaskID, count int) (int, error)

AttemptInstance gives the number of the instance that an attempt on a template gets, from 0: below(count) of the place of randomness of the attempt's seed whose names are template, the ID of the task and instance, where count is how many instances the template has, from 1 to MaxInstances (format/README.md, sections 22 and 23; R60 spec). Nothing else draws from that place, so the same package and the same seed give the same instance (R03 spec). The instances are numbered in the order of the odometer, as the package carries their numbers.

api draws the seed from a cryptographic source when the attempt begins and passes it here as a number; neither the seed nor the words of the place reach the learner's device, since the words show the seed (format/README.md, section 22). A count outside its domain gives ErrDomain, and so does an ID that is no name of a place: empty, or holding | or what is not UTF-8. The ID of a valid task is neither (common.schema.json).

func Inputs added in v0.1.20

func Inputs(task formatv0.Task) []formatv0.TemplateName

Inputs gives the names of the numbers that the solver of a template gets on each instance, in the order of their names, compared by code units: each parameter and derived number whose placeholder stands in an open field of the template — the statement, the givens, the unknown, the text of an item, a text piece of its line, an option of an answer slot bound choice (format/README.md, sections 6 and 24). A number that only a closed field shows — a key, a trap value, the solution — is not among them, so the solver solves the task that the learner sees and cannot read an answer that an expression already gives. The open view is that of the template as it is written, as spec's second implementation builds it.

A task that is no template gives none, and a string that breaks task.placeholders gives none of its own.

func Instance added in v0.1.19

func Instance(task formatv0.Task, numbers formatv0.Numbers) (formatv0.Task, error)

Instance gives the instance of a template with the numbers of one of its instances: the task with every placeholder replaced by its number, in decimal digits with - before a negative one, and every doubled brace by one, in a single pass, without its template, and with the template's id (format/README.md, section 23). It evaluates no expression and runs no Starlark: api puts in the numbers that the package carries, picked by AttemptInstance, and the open view of the instance is openview.Task of it (section 25).

The error is for a task that is no template, a string of it that breaks task.placeholders, and a placeholder whose number numbers does not give. The instance is not checked against the schema of a task: the check of a module holds every instance of a template to it, by task.instances.

func Shown added in v0.1.19

func Shown(t formatv0.Template, numbers formatv0.Numbers) string

Shown writes the numbers of an instance of a template as a breach names the instance: its parameters, in the order of their names, each with its number, as in a = 1, b = 4. A name that numbers does not give is left out.

Types

type Breach added in v0.1.19

type Breach struct {
	Rule, Pointer, Message string
}

A Breach is a reason that a template breaks a rule of templates: its Rule, one of RuleNames, RuleExpressions, RulePlaceholders, RuleInstances and RuleSolver; the value of the task that breaks it, as a JSON Pointer in URI fragment form, such as #/template/derived/b; and what breaks it.

func Instances added in v0.1.19

func Instances(ctx context.Context, task formatv0.Task) ([]formatv0.Numbers, []Breach, error)

Instances counts the instances of a template and gives the numbers of each, in their order: every parameter, every derived number and every result of the solver of the instance, by its name (format/README.md, sections 23 and 24). The combinations of the parameters come in the order of an odometer — the parameters in the order of their names, the first changing slowest, each through its domain upwards —, and on each the derived numbers are computed and then the constraint, in the sandbox of Starlark; those for which the constraint holds, or all of them when there is none, are the instances. A solver then runs on them in their order, on one thread of its own, and its results join the numbers of each.

A template that breaks a rule of templates gives its breaches and no numbers, in the order of spec's second implementation: every breach of its names, its expressions, its placeholders and the program of its solver; and only when none of them breaks, those of its combinations — every empty domain, or too many combinations, or the first combination on which an expression fails or a derived number lies past ±(2^53 − 1), where the count stops, or none that gives an instance; and only when it has instances, that of its solver on the first instance where it fails, or before the first. A task that is no template gives neither.

The count looks at ctx before each combination, and the solver runs with it, on the caller's goroutine; how many templates the caller counts at once is its own to say (R11). The error is that of ctx when ctx is done before the count ends, and is no breach: there are then neither numbers nor breaches. Instances may be called from many goroutines at once, each on a template of its own or the same.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL