ceremony

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 14 Imported by: ? modules, 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.

README

ceremony

A language and an engine for the behaviour of things that have state and are told what happens to them. An entity carries state; a fact is told to it when something happens; a state is put on it for a while; a role says what it does about either — rules that fire within a pass and plans that run over time — and what a rule or a plan asks for is a command, carried by its type to whoever carries it out. Nothing is a callback: a rule is a value saying who, when, on whom and what, checked as it is built; the engine runs it.

It was carved out of a game engine, where the entities are units, cells and the sky, and reads as well over orders, tickets and cases: an entity is a case, a fact an event, a state a status with a duration, a role a policy, a rule a reaction, a plan a workflow with its waits, a command a service call. The store of state is behind a contract (store): the engine reads an entity's facts and tags off the blocks a store hands it and writes into the places it stages; the one binding is ceremony/goke, over the goke ECS, the one package that imports it.

The dictionary

word what it is in code
entity a thing with identity carrying state a uid.UID64 and its components
fact what happened to an entity, carried until it goes fact.Fact marks the type
message a fact with a sender fact.From embedded in a command
moment what a pass perceives of an entity, handed to rules host.About, Met
places entities a host tells of a moment, of a kind its library names host.NewPlacing, Places
state an effect: on for a while, with a marker, turning knobs effect.Spec, Effect.Mark()
knob a component an effect turns and its owner only reads effect.Knob, effect.Alter[T]
role a behaviour an entity plays: the rules it obeys ceremony.Part, a bit of cond.Roles
word a predicate of a moment or a fact, with its side cond.NewWord, .OfOther()
condition who is in what state cond.Self.If(x), Other, At(places), On(o)
step what is done, said of whom act.Self.Do(cmd), Put(e), Take(e), Hold(e)
command a request carried by type to its handler command.Command, Queue, Carrier
rule a reaction within a pass act.Branch[Moment]{Name, When, Then}
plan a process over time on the entity's mind plan.New, plan.Loop[F], plan.Self.Wait
host the pass catching a moment and running its rules host.Rules, PairRules, StepRules

A rule

A rule is a sentence: who (the role), when (the condition), on whom and what (the steps). This one is from the game it comes from: Sighting is a moment its vision pass catches (who sees whom), traveller a role, talking and talked effects, Begin a command its dialogue pass carries out.

host := ceremony.NewPart("host", hostTag).Obeys(
	act.Branch[vision.Sighting]{
		Name: "talk",
		When: cond.Other.If(traveller).
			And(cond.Self.If(cond.Not(talking))).
			And(cond.Self.If(cond.Not(talked))),
		Then: act.Self.Do(dialog.Begin{}),
	},
	act.Branch[vision.Sighting]{
		Name: "part",
		When: cond.Self.If(vision.SeesNobody()),
		Then: act.Self.Take(talking),
	},
)

A rule holds no Go code but its words: vision.SeesNobody() is a cond.Word of the moment, made with cond.NewWord. A rule fires at its moment, does its steps within the pass and remembers nothing; its memory is an effect.

A plan

A plan runs over time on the entity's mind, in loops: Then is run from the start as When comes to hold, Until ends it, Timeout fails it. A loop of a fact (Loop[Arrived]) begins once as the fact comes and runs to the end; one of any runs while its When holds. From the same game: MoveTo, StepAside and Onward are commands its navigation carries out, Arrived and Blocked the facts it tells, Stuck a word of Blocked, alarm an effect on the world's own entity.

guard := plan.New("guard", plan.OneOf(
	plan.Loop[any]{
		Name:    "to the gate",
		When:    cond.On(world).If(alarm),
		Then:    plan.Self.Do(navigation.MoveTo{To: ceremony.Named("gate")}),
		Until:   cond.Self.If(navigation.Arrived{}),
		Timeout: 20 * time.Second,
	},
	plan.Loop[navigation.Blocked]{
		Name: "blocked",
		When: cond.Self.If(navigation.Stuck()),
		Then: plan.Self.Do(navigation.StepAside{}),
	},
	plan.Loop[navigation.Arrived]{
		Name: "rest",
		When: cond.Self.If(cond.Always),
		Then: plan.Self.Wait(2 * time.Second),
	},
	plan.Loop[any]{
		Name:  "patrol",
		When:  cond.Self.If(cond.Always),
		Then:  plan.Self.Do(navigation.Onward{}),
		Until: cond.Self.If(navigation.Arrived{}),
	},
	plan.Loop[any]{Name: "idle", When: cond.Self.If(cond.Always), Then: plan.Self.Idle()},
))

OneOf is checked every step from the top, an earlier loop taking over from a later one once it can; a plan done begins again. A plan talks to another entity with a message, a command embedding fact.From given with plan.Other.Do(msg): it lands on the other as a fact, and a loop of its type is the answer. The language is in doc/ceremony.md.

The layers

  • The language — cond (conditions), act (steps and the branch), plan (loops and what lasts), effect (states and knobs), and the root ceremony (roles, the commands about states, who an entity is called).
  • The engine — internal/steps runs the trees of steps on minds and at moments; host is the pass's side: the hosts of rules and the Tick they hand the rules.
  • The store — store is the contract: a Row is a block of entities, an array a column, which the engine indexes and nothing else; Facts stages what it writes; Mind is a plan's state on the entity. comp names a component for a kind's template, tag the families of bits. goke is the binding over the goke ECS: its Columns hand the engine each chunk's arrays out of goke's own accessors, its Effects run the effects, its Plans the plans, its Spawner writes a kind's components, all through goke's queries and command buffers.
  • Commands — command: a queue a type, a carrier that sorts them, an issuer.

Plugging in

  • Perceive: write a moment type (Who() the entity; Whom for a pair; the places it has, told by Tick.Places, of a kind host.NewPlacing names), keep a host.Rules[M] (PairRules for pairs, StepRules for a moment of the whole), Bind it to the columns of the pass's query (goke.NewColumns(qb)) and Run it over every chunk (cols.Row(cursor)) with a host.Tick.
  • Tell facts: put a component marked fact.Fact on the entity when the thing happens and take it off when it is over; plans begin on it and wait for it.
  • Define states and roles: effect.New(name) then Define(name, effect.Spec{...}), run by the binding (goke.NewEffects(register), its Module() installed); ceremony.NewPart(name, tag).Obeys(rules...); a kind carries ceremony.Plays(roles...); ceremony.Deliver(hosts, roles...) hands every rule to the host that catches its moment, failing with host.ErrUnhosted for one none does.
  • Carry commands: a command.Queue[C] a type, given to a command.Carrier, which the host.Tick hands the rules; drain it in the handler's pass. A command about a state (ceremony.Put(e).On(whom)) is carried out by whoever owns the target.

What is marked and asserted

A type is a fact by its method Fact(), a knob by Knob(), a command by Command() — marks never called, confirmed beside the type (var _ fact.Fact = Arrived{}). A moment is one by its Who(), a pair by Whom; one has places of a kind its host.Placing takes. What the grammar cannot run is refused as the branch is built, by the branch's name: a word of the wrong side, a fact in a When, At in a plan or on a moment without those places, a loop on a type that is no fact.

Install

go get github.com/kjkrol/ceremony

Requires Go 1.27.

Licence

MIT.

Documentation

Overview

Package hosts hands rules to the hosts of the moments they are of.

Package ceremony is a language and an engine for the behaviour of things that have state and are told what happens to them. An entity carries state; a fact is told to it when something happens (package fact); a state, an effect, is put on it for a while and turns knobs (package effect); a role says what it does about either — rules that fire within a pass at the moments it catches (package act, their conditions package cond) and plans that run over time on its mind (package plan) — and what a rule or a plan asks for is a command, carried by its type to whoever carries it out (package command). The hosts of rules, the pass's side, are package host; the components an entity is made of, package comp and package tag. This package ties them together: the roles whose players obey rules, the commands about effects, who an entity is called.

desk := ceremony.NewPart("desk", deskTag).Obeys(act.Branch[Review]{
	Name: "escalate",
	When: cond.Self.If(overdue).And(cond.Self.If(cond.Not(escalated))),
	Then: act.Steps(act.Self.Put(escalated), act.Self.Do(Notify{To: "lead"})),
})

Roles

A Part is a role: the rules those playing it obey (Part.Obeys), narrowed to its players. An entity plays roles through one component, Plays; NewPart makes a role out of a tag of cond.Roles, and Deliver hands every rule of every role to the host catching its moment.

Commands

A Command is what somebody wants done about an effect, written as a sentence: Put, Take or Toggle an effect, On whom, By whom set off, For how long. A user gives one, a rule gives one with act.Self.Do, and an entity gives every Command whose By names it with Trigger. Whom a command is for is a Whom: Named, Group, ID or World; an entity is called by its Label.

Index

Constants

This section is empty.

Variables

View Source
var World = Whom{/* contains filtered or unexported fields */}

World is the world's own entity: the state of the whole game.

Functions

func Deliver

func Deliver(among []host.Host, rules ...act.Rule) error

Deliver hands each rule, a role's each of its own, to the first of among that takes it, the next tried while one refuses with host.ErrUnhosted. A rule none takes is host.ErrUnhosted naming the rule; any other error stops at once.

Types

type Command

type Command struct {
	Verb   Verb
	Effect effect.Effect
	Whom   Target
	Source Whom          // nobody for none
	Lasts  time.Duration // zero: as the effect's Spec says
	Name   string        // empty for one not in the Stage's register
}

Command is a command about an effect and whom it is for, written as a sentence: Put(open).On(Group("trapdoors")).By(Named("lever")).For(pulse); a rule gives it with act.Self.Do. A step on whom a branch acts is act.Self.Put or act.Self.Take.

func Put

func Put(e effect.Effect) Command

Put puts e on whoever On names.

func Take

func Take(e effect.Effect) Command

Take takes e off whoever On names.

func Toggle

func Toggle(e effect.Effect) Command

Toggle takes e off whoever On names where any of them is under it, and puts it on them all otherwise.

func (Command) By

func (c Command) By(source Whom) Command

By says who sets the command off: an entity bearing the name or the group, as it gives itself Trigger.

func (Command) Command

func (Command) Command()

func (Command) Defined

func (c Command) Defined() bool

Defined reports whether the command was defined in a Stage's register.

func (Command) For

func (c Command) For(d time.Duration) Command

For says how long a Put lasts, in place of what the effect's Spec says.

func (Command) On

func (c Command) On(whom Target) Command

On says whom the command is for.

func (Command) Routed

func (c Command) Routed() command.Command

Routed is the command as the plugin of its target takes it. It panics for a command that names no target.

func (Command) String

func (c Command) String() string

String says what the command does.

type Label

type Label struct{ Name, Group uint64 }

Label is what an entity is called: its own name, borne by it alone, and the group it is in with others, each hashed, zero for none.

func LabelOf

func LabelOf(name, group string) Label

LabelOf is the Label of an entity named name in the group group, either empty for none.

type Part

type Part struct {
	// contains filtered or unexported fields
}

Part is a role an entity plays: the rules those playing it obey, given to a kind with Plays.

func NewPart

func NewPart(name string, t tag.Tag[cond.Roles]) *Part

NewPart is the role named name with the tag t of cond.Roles, for the world's register of roles.

func (*Part) ForRole

func (r *Part) ForRole(role cond.Role) act.Rule

ForRole is the role's rules narrowed to the players of role too (act.Rule).

func (*Part) Hosted

func (r *Part) Hosted() any

Hosted is the role itself: its host takes its rules one by one (host.Hosted).

func (*Part) Obeys

func (r *Part) Obeys(rules ...act.Rule) *Part

Obeys adds rules those playing the role obey, each narrowed to them.

func (*Part) Rules

func (r *Part) Rules() []act.Rule

Rules are the rules the role's players obey.

func (*Part) String

func (r *Part) String() string

String names the role.

func (*Part) Tag

func (r *Part) Tag() tag.Tag[cond.Roles]

Tag is the role's tag of cond.Roles (cond.Role).

type Played

type Played struct {
	comp.Template[tag.Tags[cond.Roles]]
	// contains filtered or unexported fields
}

Played is what Plays makes: the roles' tags as a kind's component.

func Plays

func Plays(roles ...*Part) Played

Plays is the component of an entity playing roles, for a kind's Spec: every role in one.

func (Played) Parts

func (p Played) Parts() []*Part

Parts are the roles played.

type Router

type Router interface {
	Target
	Route(c Command) command.Command
}

Router is a Target of a plugin's own: Route is the command that plugin carries out for c.

type Target

type Target interface{ Target() }

Target is whom a Command is for: an Whom, or a plugin's own, which is a Router.

type Trigger

type Trigger struct{}

Trigger is the command by which an entity sets off every Command whose By names it: a lever pulled gives itself act.Self.Do(Trigger{}).

func (Trigger) Command

func (Trigger) Command()

type Verb

type Verb uint8

Verb is what a Command does with its effect.

const (
	Puts Verb = iota
	Takes
	Toggles // takes it off where any target is under it, else puts it on
)

type Whom

type Whom struct {
	// contains filtered or unexported fields
}

Whom says which entities a command is for, or who sets it off: those Named, those in a Group, those of an ID, or the World itself.

func Group

func Group(names ...string) Whom

Group are all the entities in these groups.

func ID

func ID(ids ...uid.UID64) Whom

ID are the entities of these identifiers, for one that has no name.

func Named

func Named(names ...string) Whom

Named are the entities bearing these names, one each.

func (Whom) Each

func (w Whom) Each(fn func(said string, borne func(Label) bool))

Each calls fn with every name and group it names, as written, and whether a Label bears it.

func (Whom) Holds

func (w Whom) Holds(l Label) bool

Holds reports whether an entity labelled l is among those it names.

func (Whom) IDs

func (w Whom) IDs() []uid.UID64

IDs are the identifiers it names (ID).

func (Whom) IsWorld

func (w Whom) IsWorld() bool

IsWorld reports whether it is the World.

func (Whom) Nobody

func (w Whom) Nobody() bool

Nobody reports whether it names no one: the zero Whom.

func (Whom) String

func (w Whom) String() string

String says whom, as written.

func (Whom) Target

func (Whom) Target()

Target marks Whom as whom a command may be for.

Directories

Path Synopsis
Package act is what a rule does: the Then of a Branch, every step said of whom it is done by or to, and the Branch itself, which given to a role is a rule.
Package act is what a rule does: the Then of a Branch, every step said of whom it is done by or to, and the Branch itself, which given to a role is a rule.
Package command is how anything is asked for: a command is a value carried by its type to the one handler whose queue takes it, from a user and from an entity alike, and waits there for the handler's pass.
Package command is how anything is asked for: a command is a value carried by its type to the one handler whose queue takes it, from a user and from an entity alike, and waits there for the handler's pass.
Package comp is how a template of entities names one component and where its value comes from: the same for every entity made from it (Const), read from each entity's own row (Load), the tags of one family (Tagged), the markers of one (Marks), or a default of the store's roster left out (Without).
Package comp is how a template of entities names one component and where its value comes from: the same for every entity made from it (Const), read from each entity's own row (Load), the tags of one family (Tagged), the markers of one (Marks), or a default of the store's roster left out (Without).
Package cond is the When of a branch: who is in what state, every clause saying whom it is about.
Package cond is the When of a branch: who is in what state, every clause saying whom it is about.
Package effect puts states on entities for a while: each effect with its own marker, tags granted, components altered and restored.
Package effect puts states on entities for a while: each effect with its own marker, tags granted, components altered and restored.
Package fact is what happens to an entity: a fact is told to it and carried until it goes, a loop of a plan begins on it or waits for it; a message is a fact with its sender.
Package fact is what happens to an entity: a fact is told to it and carried until it goes, a loop of a plan begins on it or waits for it; a message is a fact with its sender.
Package goke binds ceremony to the goke ECS, the one package of the library that imports it: the store that keeps the entities, reads them for the engine and stages what it writes, every read and write through goke's own queries and command buffers.
Package goke binds ceremony to the goke ECS, the one package of the library that imports it: the store that keeps the entities, reads them for the engine and stages what it writes, every read and write through goke's own queries and command buffers.
Package host is the pass's side of the rules: a pass that perceives a moment of its entities keeps a host of that moment, binds it to the columns of its query (store.Columns) and runs it over every block of entities (store.Row), and the host runs the rules given to it.
Package host is the pass's side of the rules: a pass that perceives a moment of its entities keeps a host of that moment, binds it to the columns of its query (store.Columns) and runs it over every block of entities (store.Row), and the host runs the rules given to it.
internal
steps
Package steps runs the steps of rules and plans: the nodes packages cond, act and plan build, laid out as a tree, run at a moment within a pass (Instant) or every step on the entities' minds (Plans).
Package steps runs the steps of rules and plans: the nodes packages cond, act and plan build, laid out as a tree, run at a moment within a pass (Instant) or every step on the entities' minds (Plans).
Package plan is what an entity does over time: loops run on its mind every step, made of the same steps a rule has and of what lasts.
Package plan is what an entity does over time: loops run on its mind every step, made of the same steps a rule has and of what lasts.
Package store is the contract between ceremony's engine and the store that keeps the entities, what a binding such as ceremony/goke implements: the engine reads an entity's facts and tags off a Row the store hands it a block at a time, writes a fact into the place the store's Facts stage for it, and keeps a plan's state in the Mind the store carries on the entity.
Package store is the contract between ceremony's engine and the store that keeps the entities, what a binding such as ceremony/goke implements: the engine reads an entity's facts and tags off a Row the store hands it a block at a time, writes a fact into the place the store's Facts stage for it, and keeps a plan's state in the Mind the store carries on the entity.
Package tag is the tags an entity carries: a family's Tags, a component of up to MaxTagsPerFamily bits, each a Tag its owner defines by name and the store saves by name.
Package tag is the tags an entity carries: a family's Tags, a component of up to MaxTagsPerFamily bits, each a Tag its owner defines by name and the store saves by name.

Jump to

Keyboard shortcuts

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