From 32b16a23a7ca7080b32a2948cd7518053125dac9 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Mon, 28 Sep 2026 00:20:49 +0100 Subject: Let a fold in a column read the column's row A count, sum, max or min inside a table's column may now name the row the column is evaluated for: per branch, the sum of its accounts (sum(a.balance for a in accounts where a.bid == b.bid)), or per account, how many are richer. The column's row inside the fold compiles to OUTER_ROW, which Pure's verifier accepts only in a fold that runs in a column; the fold's own item stays ROW. This is a correlated subquery, the form SQL writes GROUP BY and self-joins with. --- tests/check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/check.py') diff --git a/tests/check.py b/tests/check.py index 98d6e37..84fc9bd 100644 --- a/tests/check.py +++ b/tests/check.py @@ -196,8 +196,6 @@ DIAGNOSTICS = [ (LIST + 'view v = count(x in at)\n', '6:10', "'at' is not a list"), ('record T {\n t: text\n}\nstate xs: list of T\nview v = sum(x.t for x in xs)\n', '5:14', 'sum, max and min take numbers, not text'), - (LIST + 'view w = each r in xs {\n n = count(x in xs where x.a == r.a)\n}\n', '7:34', - "'r' is the column's row; a count, sum, max or min reads only its own item"), (LIST + 'fn f(n) = count(x in xs where x.a == n)\nview v = f(1)\n', '6:38', "'n' is a parameter outside this count, sum, max or min"), (LIST + 'view v = sum(dt for x in xs)\n', '6:14', 'dt is not available in count, sum, max or min'), @@ -234,6 +232,8 @@ DIAGNOSTICS = [ ] ACCEPTED = [ + # A fold in a column reads the column's row too (a correlated subquery). + LIST + 'view w = each r in xs {\n n = count(x in xs where x.a == r.a)\n}\n', SENDS + 'on buy {\n n = n + 1\n send ordered { to: { city: "Seoul" }, count: buy.count, item: buy.item }\n}\nview sent = n\n', # fns named like folds stay calls, and max of two values stays max 'fn sum(a, b) = a + b\nfn count(x) = x\nview v = sum(1, count(2)) + max(3, 4) + min(\n 5,\n 6\n)\n', -- cgit v1.2.3