✓
Passing This code compiles and runs correctly.
Code
// TEST: std/kernel — `reduce` composes with `self` UNDER `step` in one init.
//
// Each step mutates every mass (self), then reduce aggregates the mutated state
// through DECLARED accumulator slots (`<name>[<type>]`). This is the realistic
// shape a simulation needs: evolve the data AND answer a question about it in
// the same pass. Expected: self mass+=1.0 over 3 steps of masses [1,2] yields
// per-step sums [5,7,9] → total=21 count=6.
import std/kernel
import std/io
std/kernel:shape(Pt) {
mass: f64,
}
std/kernel:init(Pt) {
{ mass: 1.0 },
{ mass: 2.0 },
}
| kernel k |> std/kernel:step(0..3)
| step |> std/kernel:self { k.mass += 1.0 }
|> std/kernel:reduce {
total_mass[f64]
count[i32]
total_mass += k.mass
count += 1
}
| reduce r |> std/io:print.blk {
total={{ r.total_mass:f }} count={{ r.count:d }}
}
Actual
total=21 count=6
Expected output
total=21 count=6
Flows
flow ~shape click a branch to expand · @labels scroll to their anchor
shape (expr: Pt, source: mass: f64,)
flow ~init click a branch to expand · @labels scroll to their anchor
init (expr: Pt, source: { mass: 1.0 },
{ mass: 2.0 },)
Test Configuration
MUST_RUN