feat(lang): 27.3 - a reducer on a table's row: reducer T in S.table on A, @Target, Row<T>, @RowVerb, @Column

An action names one row of a ludic.base Table<T> by its handle, in a field marked @Target, and
`reducer Deer in Herd.deer on Spook(r: mut Row<Deer>, n: Noise, a: Spook)` runs once, for that row
alone (the table may sit down a path, S.w.tab). The drain resolves the handle (tb_row) and hands the
reducer a Row<T> - new in ludic.base: tb, row, h, rec - that the queue keeps, one per row reducer,
filled in place, so a targeted action allocates nothing; a stale handle runs nothing, and
LUDIC_ACTIONS_LOG=1 prints a line for it (@alloc_ok). Row reducers order among an action's by their
state's name, then the table's path.

Checked at compile time (actions_rows.ludic): the row reaches r.rec and r.h only - r.tb / r.row
refused, the view never assigned, stored, copied or handed on except to a @RowVerb (a function of
the record's own module taking Row<T> first; any other function taking a row is refused); a field
marked @Column (a table column mirrors it) is not written through r.rec; only the module owning the
state declares a row reducer; one @Target, an int, per action; the states between the row and the
action are read. `mut` is allowed on a Row<T> parameter.

ludic schema's code section gains row_reducers (record, table, state, action, target, predicted,
net, module, at) and row_verbs (name, record, module, at), and every action its target; row
reducers are left out of `reducers`. ludic deps and ludic-lsp name a row reducer
`reducer Deer in Herd.deer on Spook`. vocab: @Target, @Column, @RowVerb; docs/language pages;
LANGUAGE.md "A reducer on a row"; examples actions/rows and ten rejects; test.ludic feat, reject and
schema cases (not run); changes/row-reducers.md. Reseeded; bootstrap-cfree fixpoint holds (307497
lines); Maroon Lake's `ludic build --check` is clean against this tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-30 16:14:59 +03:00
parent d22abae476
commit ab0b84b87e
37 changed files with 125923 additions and 110956 deletions

View file

@ -0,0 +1,19 @@
---
id: annot-column
name: @Column
category: annotations
kind: annotation
tokens: @Column
sig: property Deer { @Column x: float = 0.0 }
tip: A record's field a column of its table mirrors: written only by a @RowVerb.
order: 82
---
<code>@Column</code> marks a field of a table's record that one of the table's columns mirrors - a position, a kind, whether it is alive - so an index reads it. Inside a row reducer it is not written through <code>r.rec</code>: a <code>@RowVerb</code> writes it, and the column and its indexes with it.
```ludic
property Deer {
@Column x: float = 0.0
fear: int = 0
}
```

View file

@ -0,0 +1,19 @@
---
id: annot-rowverb
name: @RowVerb
category: annotations
kind: annotation
tokens: @RowVerb
sig: @RowVerb function deer_move(r: mut Row<Deer>, x: float) -> void
tip: A verb of a table's row: the only function a row reducer hands its row to.
order: 83
---
<code>@RowVerb</code> marks a function that changes one row of a table, taking the <code>Row&lt;T&gt;</code> first. It is declared in the module that owns the record, reaches the row's table (<code>r.tb</code>, <code>r.row</code>) to keep its columns and indexes, and is the only function a row reducer may hand its row to; a function not marked so is refused a row.
```ludic
@RowVerb function deer_move(r: mut Row<Deer>, x: float) -> void {
r.rec.x = x
tb_set_f(r.tb, 0, r.row, x)
}
```

View file

@ -0,0 +1,16 @@
---
id: annot-target
name: @Target
category: annotations
kind: annotation
tokens: @Target
sig: action Spook { @Target who: int = -1 }
tip: An action's field holding the handle of the one table row it names.
order: 81
---
<code>@Target</code> marks the field of an <code>action</code> that holds a row's handle - what <code>tb_add</code> returned. A row reducer (<code>reducer Deer in Herd.deer on Spook</code>) runs once, for that row alone, and a handle whose row is gone runs nothing. An action has one: several rows are one <code>dispatch</code> per handle.
```ludic
action Spook { @Target who: int = -1, by: int = 1 }
```

View file

@ -4,8 +4,8 @@ name: reducer
category: structure
kind: keyword
tokens: reducer
sig: reducer State on Action(st: mut State, reads..., a: Action) { ... }
tip: Applies an action to one state; it may read others.
sig: reducer State on Action(st: mut State, reads..., a: Action) { ... } / reducer Record in State.table on Action(r: mut Row<Record>, reads..., a: Action) { ... }
tip: Applies an action to one state, or to the one table row its @Target names; it may read others.
order: 62
---
@ -18,3 +18,12 @@ reducer Pos on Move(p: mut Pos, a: Move) {
p.x = p.x + a.dx
}
```
Written <code>in State.table</code>, a reducer runs for the one row of that <code>Table&lt;Record&gt;</code> the action's <code>@Target</code> field names: it is handed a <code>Row&lt;Record&gt;</code>, reaches <code>r.rec</code> and <code>r.h</code>, and changes a field a column mirrors (<code>@Column</code>) only through a <code>@RowVerb</code>. A handle whose row is gone runs nothing.
```ludic
# doc-check: skip — needs ludic.base's Table
reducer Deer in Herd.deer on Spook(r: mut Row<Deer>, a: Spook) {
r.rec.fear += a.by
}
```