feat(lang): 0.R1 - actions and reducers
action Name { fields } is a typed record; reducer State on Action(s: mut State, a: Action) { ... }
in the module that owns the state takes exactly that state and the action (a second state is
refused); dispatch Action { fields } queues one from anywhere, the queue supplied by the runtime.
The queue is drained at the end of every phase of the frame loop, after every phase of ludic.base's
core_tick_all, and by drain_actions(): in dispatch order, each action's reducers in the order of
their states' names, an action a reducer dispatches queued behind, a queue still growing after 64
rounds stopped with the action named. Examples actions/pack, phases, runaway; rejects for a second
state, a reducer on a non-action and an unknown dispatch; ludic.base's actions_test; LANGUAGE.md.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3a87d02696
commit
808c4a6f7a
19 changed files with 415 additions and 1 deletions
5
examples/rejected/dispatch_unknown.ludic
Normal file
5
examples/rejected/dispatch_unknown.ludic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# 0.R: only an action is dispatched
|
||||
program DispatchUnknown {
|
||||
action Buy { cost: int }
|
||||
entry { dispatch Sell { cost: 1 } }
|
||||
}
|
||||
7
examples/rejected/reducer_not_action.ludic
Normal file
7
examples/rejected/reducer_not_action.ludic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# 0.R: a reducer is on an action
|
||||
program ReducerNotAction {
|
||||
state Pack { n: int = 0 }
|
||||
property Buy { cost: int = 0 }
|
||||
reducer Pack on Buy(p: mut Pack, a: Buy) { p.n += 1 }
|
||||
entry { print(1) }
|
||||
}
|
||||
8
examples/rejected/reducer_two_states.ludic
Normal file
8
examples/rejected/reducer_two_states.ludic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# 0.R: a reducer takes its own state and the action; what else it needs rides in the action
|
||||
program ReducerTwoStates {
|
||||
state Pack { n: int = 0 }
|
||||
state Wallet { cash: int = 0 }
|
||||
action Buy { cost: int }
|
||||
reducer Pack on Buy(p: mut Pack, w: mut Wallet) { p.n += 1 }
|
||||
entry { print(1) }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue