✓
Passing This code compiles and runs correctly.
Code
// A query branch can TAKE its matched row — "sweep the dead and remove them".
// Two things this pins:
// 1. Addressing: `take(arena[entity])` inside a query body addresses the
// currently-swept row. `entity` there is the query's row cursor, rewritten
// to the qbody cursor (not a stray identifier leaking as raw host code).
// 2. swap-remove during the sweep: take drops the LAST row into the freed
// slot, so the sweep must re-check that index instead of advancing past
// the row that just moved in. Row order [5, 50, 8] is the adversarial
// case — taking row 0 (hp 5) swaps hp 8 into slot 0, already passed; the
// sweep must revisit it. Both 5 and 8 are taken; 50 survives the guard.
import std/io
import std/store
std/store:new(arena) { hp: i64 }
std/store:insert(arena) { hp: 5 }
| row _ |> _
| full |> _
std/store:insert(arena) { hp: 50 }
| row _ |> _
| full |> _
std/store:insert(arena) { hp: 8 }
| row _ |> _
| full |> _
std/store:query(arena)
! query { entity.hp } when hp <= 10 |> std/store:take(arena[entity])
| item i |> std/io:print.ln("took {{ i.hp:d }}")
Actual
took 5
took 8
Expected output
took 5
took 8
Flows
flow ~new click a branch to expand · @labels scroll to their anchor
new (expr: arena, source: hp: i64)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (expr: arena, source: hp: 5)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (expr: arena, source: hp: 50)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (expr: arena, source: hp: 8)
flow ~query click a branch to expand · @labels scroll to their anchor
query (expr: arena)
Test Configuration
MUST_RUN