A registry marked `@Machine(Deer.mood)` is the transitions of a machine over that enum field of the records a state's Table<Deer> holds. Its record has from and to (the enum's variants), on: string (an action's name, "" for a transition the tick asks), guard: fn(Row<Deer>, reads...) -> bool and enter: fn(Row<Deer>, reads...) -> void; the states are the enum's variants and the start is the field's default. The rows are data (an .lres or defs), the names the studio already edits. Written by the compiler (machines.ludic, machines_write.ludic): for each action an `on` names, a row reducer in the registry's file (named ..__machine__DeerSteps, so it sits beside the program's own row reducer on the same action, after it): the row's state, the first transition from it on that action whose guard passes, the field set, enter run - guards and enters called by name. When a row leaves a state on a guard alone, `state DeerStepsMachine` (the kept row view) and deer_steps_tick(m: mut DeerStepsMachine, s: mut Herd, reads...), one transition a row a tick. Nothing allocates. The table is the whole machine: the field written anywhere else - an assignment, or a `machine` block's become over it - is a type error (check_stmt.ludic, ck_machine_write). Guards and enters take the row first, are the record's module's, keep a row reducer's rules (and may be handed the row); a guard writes nothing through it. The graph is checked, each error at its row (in the .lres when the rows are there): a state never reached from the start, a state with no way out, an `on` naming no action or an action with no @Target, a self-transition with no guard, two ways out of a state on one trigger behind an unguarded first. Also refused: @Machine off a registry, a field that is not a plain enum with a default, a @Column field, no table (or two) of the record, a transitions record of another shape, a machine outside its table's state's module. ludic schema's code section gains `machines` (registry, record, field, enum, table, start, states, actions, tick, module, at); ludic deps names a machine's reducer `reducer Deer in Herd.deer on Spook (machine DeerSteps)`. vocab @Machine; docs annot-machine, kw-machine; LANGUAGE.md "A machine as data"; examples actions/machine (+ deer_steps.lres) and ten rejects; test.ludic feat, reject and schema cases (not run); changes/machines.md. Reseeded; bootstrap-cfree fixpoint holds (317642 lines); Maroon Lake's `ludic build --check` is clean against this tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 KiB
3 KiB
bump: minor
type: feat
A state machine as data: @Machine(Record.field) (phase 27.1). A registry marked
@Machine(Deer.mood) is the transitions of a machine over that enum field of the records a state's
Table<Deer> holds: its record has from and to (the enum's variants), on: string (an action's
name, "" for a transition the tick asks), guard: fn(Row<Deer>, reads...) -> bool and
enter: fn(Row<Deer>, reads...) -> void; the states are the enum's variants and the start is the
field's default. Its rows are data - an .lres or defs - so the studio edits the machine as a graph.
- The compiler writes the machine. For each action an
onnames, a row reducer in the registry's file (reducer Deer in Herd.deer on Spook, beside any the program writes, after them): the row's state, the first transition from it on that action whose guard passes, the field set,enterrun. When a row leaves a state on a guard alone,state DeerStepsMachine(the kept row view) anddeer_steps_tick(m: mut DeerStepsMachine, s: mut Herd, reads...), one transition a row a tick, called from the program's system. Guards and enters are called by name; nothing allocates. - The table is the whole machine. The field is written by nothing else: an assignment to it or
a
machineblock'sbecomeover it outside the written code is a type error (Deer.mood is the machine DeerSteps's (@Machine(Deer.mood)) - it changes only by a transition in its table); a new row takes its state in itsnew. A guard and an enter take the row first, are the record's module's, and keep a row reducer's rules (r.recandr.honly, a@Columnfield only through a@RowVerb); a guard writes nothing through its row. - The graph is checked, each an error naming its row: a state never reached from the start, a
state with no way out, an
onnaming no action or an action with no@Target, a self-transition with no guard, and two ways out of a state on one trigger behind an unguarded first. Also refused:@Machineon anything but a registry, a field that is not a plain enum with a default, a@Columnfield, no table (or two) of the record, a transitions record of another shape, and a machine outside its table's state's module. ludic schema's code section gainsmachines(registry,record,field,enum,table,start,states,actions,tick,module,at); the registry carries@Machineamong its attributes.ludic depsnames a machine's reducerreducer Deer in Herd.deer on Spook (machine DeerSteps). vocab:@Machine; docsannot-machine; LANGUAGE.md "A machine as data".- Examples
actions/machine(withdeer_steps.lres); rejects for an unreachable state, no way out, an unknown action, an action with no row, a self-transition with no guard, an ambiguous trigger, a guard that writes, the field written by hand,@Machineoff a registry and a field that is no enum. Themachineblock stays for a machine that is only code.