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,12 @@
# 27.3: a field a column mirrors is written only by a @RowVerb, which keeps the column with it
import "ludic.base"
program RowReducerColumn {
property Deer {
@Column x: int = 0
fear: int = 0
}
state Herd { deer: Table<Deer> = null }
action Push { @Target who: int = -1, dx: int = 1 }
reducer Deer in Herd.deer on Push(r: mut Row<Deer>, a: Push) { r.rec.x += a.dx }
entry { print(1) }
}

View file

@ -0,0 +1,9 @@
# 27.3: a row reducer's action names its row in a field marked @Target
import "ludic.base"
program RowReducerNoTarget {
property Deer { fear: int = 0 }
state Herd { deer: Table<Deer> = null }
action Spook { who: int = -1 }
reducer Deer in Herd.deer on Spook(r: mut Row<Deer>, a: Spook) { r.rec.fear += 1 }
entry { print(1) }
}

View file

@ -0,0 +1,10 @@
# 27.3: a row is handed only to its record's @RowVerbs
import "ludic.base"
program RowReducerNotVerb {
property Deer { fear: int = 0 }
state Herd { deer: Table<Deer> = null }
action Spook { @Target who: int = -1 }
function scare(r: mut Row<Deer>) -> void { r.rec.fear += 1 }
reducer Deer in Herd.deer on Spook(r: mut Row<Deer>, a: Spook) { scare(r) }
entry { print(1) }
}

View file

@ -0,0 +1,7 @@
# 27.3: a table's rows are reduced only by the module that owns its state
import "ludic.base"
import "row_reducer_owner/herd"
program RowReducerOwner {
reducer Deer in Herd.deer on Spook(r: mut Row<Deer>, a: Spook) { r.rec.fear += 1 }
entry { print(1) }
}

View file

@ -0,0 +1,5 @@
# herd/index.ludic - the herd's state and its table; its rows are its own module's to reduce
module herd uses ludic_base
export property Deer { fear: int = 0 }
export state Herd { deer: Table<Deer> = null }
export action Spook { @Target who: int = -1 }

View file

@ -0,0 +1,9 @@
# 27.3: a row reducer takes its row, mut, first and the action last
import "ludic.base"
program RowReducerParams {
property Deer { fear: int = 0 }
state Herd { deer: Table<Deer> = null }
action Spook { @Target who: int = -1 }
reducer Deer in Herd.deer on Spook(r: Row<Deer>, a: Spook) { print(r.rec.fear) }
entry { print(1) }
}

View file

@ -0,0 +1,11 @@
# 27.3: a row reducer reaches its row's record and handle, not its table
import "ludic.base"
program RowReducerReach {
property Deer { fear: int = 0 }
state Herd { deer: Table<Deer> = null }
action Spook { @Target who: int = -1 }
reducer Deer in Herd.deer on Spook(r: mut Row<Deer>, a: Spook) {
tb_remove(r.tb, r.h)
}
entry { print(1) }
}

View file

@ -0,0 +1,9 @@
# 27.3: a row reducer names a Table of its record in its state
import "ludic.base"
program RowReducerTable {
property Deer { fear: int = 0 }
state Herd { count: int = 0 }
action Spook { @Target who: int = -1 }
reducer Deer in Herd.count on Spook(r: mut Row<Deer>, a: Spook) { r.rec.fear += 1 }
entry { print(1) }
}

View file

@ -0,0 +1,10 @@
# 27.3: a row reducer writes its row alone; the states it declares are read
import "ludic.base"
program RowReducerWritesState {
property Deer { fear: int = 0 }
state Herd { deer: Table<Deer> = null }
state Noise { loud: int = 0 }
action Spook { @Target who: int = -1 }
reducer Deer in Herd.deer on Spook(r: mut Row<Deer>, n: mut Noise, a: Spook) { n.loud += 1 }
entry { print(1) }
}

View file

@ -0,0 +1,7 @@
# 27.3: a @RowVerb takes its row first
import "ludic.base"
program RowVerbNoRow {
property Deer { fear: int = 0 }
@RowVerb function scare(n: int) -> void { print(n) }
entry { print(1) }
}

View file

@ -0,0 +1,6 @@
# 27.3: an action names one row: one @Target field
import "ludic.base"
program TargetTwice {
action Swap { @Target a: int = -1, @Target b: int = -1 }
entry { print(1) }
}