✓
Passing This code compiles and runs correctly.
Code
// Capture-as-events: BUILT 2026-06-11 (was the frontier pin for the
// dissolution; green since the [transform]proc migration). The primitives:
// - `capture { ... }` and `captured { ... }` are the SAME shape — events
// taking one SOURCE BLOCK (bare braces, no parens; ratified 2026-06-11 —
// `name { ... }` is unambiguously an invocation since `=>` took over
// branch construction, 210_047). `capture { X }` seeds, `captured { X }`
// updates, and `captured { ... }` is just an event call, so it composes
// anywhere in a chain.
// - `! as acc` binds the accumulator as an EFFECT cell — live/during the loop
// (effects fire during; the cell is mutated each iteration).
// - `| captured result` is the CONTINUATION — the after-value, handed off once.
// It is OPTIONAL (`| ?captured`): if the work happened via side effects in
// the effect-branch, you may decline the final reading (cf. `for`'s `| ?done`).
// - The `{ sum: ..., count: ... }` block is OPAQUE — the `captured` handler
// interprets it via the projector and emits per-target writes into the cell.
//
// Behavior when built: sum/count over 1, 3, 6, 8, 10; values > 5 are 6, 8, 10
// (sum = 24, count = 3, avg = 8).
import std/io
import std/control
capture { sum: @as(i64, 0), count: @as(i32, 0) }
! as acc |> for(&[_]i32{1, 3, 6, 8, 10})
! each item |> if(item > 5)
| then |> captured { sum: acc.sum + @as(i64, item), count: acc.count + 1 }
| else |> captured { acc.sum, acc.count }
| captured result |> std/io:print.ln("{{ @divTrunc(result.sum, @as(i64, result.count)):d }}")
Supporting Files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
static char *__koru_concat(const char *a, const char *b) {
size_t la = strlen(a), lb = strlen(b);
char *r = (char *)malloc(la + lb + 1);
if (!r) { fputs("koru: out of memory\n", stderr); abort(); }
memcpy(r, a, la);
memcpy(r + la, b, lb + 1);
return r;
}
static void __koru_stdout_write(const char *s) { fputs(s, stdout); }
static void __koru_stderr_write(const char *s) { fputs(s, stderr); }
static long long __koru_len_str(const char *s) { return (long long)strlen(s); }
static int __koru_streq(const char *a, const char *b) { return strcmp(a, b) == 0; }
static char *__koru_str_i64(long long v) {
char buf[32];
snprintf(buf, sizeof buf, "%lld", v);
return __koru_concat(buf, "");
}
static void __koru_stdout_write_i64(long long v) { printf("%lld", v); }
static void __koru_stderr_write_i64(long long v) { fprintf(stderr, "%lld", v); }
static void __koru_stdout_write_f64(double v) { printf("%g", v); }
static void __koru_stderr_write_f64(double v) { fprintf(stderr, "%g", v); }
static void __koru_stdout_write_f64_prec(double v, int prec) { printf("%.*f", prec, v); }
static void __koru_stderr_write_f64_prec(double v, int prec) { fprintf(stderr, "%.*f", prec, v); }
static int __koru_argc;
static char **__koru_argv;
static char __koru_readln_buf[8192];
struct __koru_comptime_Expression { char __koru_comptime; };
struct __koru_comptime_Source { char __koru_comptime; };
static _Noreturn void __koru_unreachable(const char *what) {
fflush(NULL); // buffered stdout must land before the trap (zig flushes; abort does not)
fprintf(stderr, "koru: %s\n", what);
abort();
}
static long long __koru_intcast(long long v, long long lo, long long hi) {
if (v < lo || v > hi) __koru_unreachable("@intCast out of range");
return v;
}
static unsigned long long __koru_intcast_u(unsigned long long v, unsigned long long lo, unsigned long long hi) {
if (v < lo || v > hi) __koru_unreachable("@intCast out of range");
return v;
}
static long long __koru_max_ll(long long a, long long b) { return a > b ? a : b; }
static long long __koru_min_ll(long long a, long long b) { return a < b ? a : b; }
struct __koru_slice_const_struct_Item { const struct Item *ptr; uintptr_t len; };
static void std_control_capture(void);
static void std_testing_validate_mocks(void);
static const char * std_spec_spec_revision(void);
static void std_control_capture(void) {
__koru_unreachable("std.control:capture: transform/comptime tor invoked on the C lane");
}
static void std_testing_validate_mocks(void) {
__koru_unreachable("std.testing:validate-mocks: transform/comptime tor invoked on the C lane");
}
static const char * std_spec_spec_revision(void) {
return "std/spec:0";
}
static void koru_flow_0(void) {
struct __koru_cap_acc { long long sum; int32_t count; } acc = { .sum = 0, .count = 0 };
const int32_t __koru_items3[] = { 1, 3, 6, 8, 10 };
for (size_t __koru_i3 = 0; __koru_i3 < sizeof(__koru_items3) / sizeof(__koru_items3[0]); __koru_i3++)
{
{ long long item = __koru_items3[__koru_i3]; if (item > 5) {
{ {
struct __koru_cap_acc __koru_snap = acc;
__koru_snap.sum = acc.sum + ((long long)(item));
__koru_snap.count = acc.count + 1;
acc = __koru_snap;
}
}
} else {
{ {
struct __koru_cap_acc __koru_snap = acc;
__koru_snap.sum = acc.sum;
__koru_snap.count = acc.count;
acc = __koru_snap;
}
}
} }
}
{ }
struct __koru_cap_acc result = acc;
__koru_stdout_write_i64((((result.sum) / (((long long)(result.count)))))); __koru_stdout_write("\n");}
int main(int argc, char **argv) {
__koru_argc = argc;
__koru_argv = argv;
koru_flow_0();
return 0;
}
Actual
8
Expected output
8
Flows
flow ~capture click a branch to expand · @labels scroll to their anchor
capture (source: sum: @as(i64, 0), count: @as(i32, 0))
Test Configuration
MUST_RUN