datalog: aggregate validates that agg-var appears in goal
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 37s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 37s
`count(N, Y, p(X))` silently returned `N = 1` because `Y` was never bound by the goal — every match contributed the same unbound symbol which dl-val-member? deduped to a single entry. Similarly: sum(S, Y, p(X)) => raises "expected number, got symbol" findall(L, Y, p(X)) => L = (Y) (a list containing the unbound symbol) count(N, Y, p(X)) => N = 1 (silent garbage) Added a third validator in dl-eval-aggregate: the agg-var must syntactically appear among the goal's variables. Error names the variable and the goal and explains why the result would be meaningless. 1 new test; conformance 263/263. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -113,6 +113,14 @@
|
||||
(error (str "datalog aggregate (" op
|
||||
"): third arg must be a positive literal, got "
|
||||
goal)))
|
||||
((not (dl-member-string?
|
||||
(symbol->string agg-var)
|
||||
(dl-vars-of goal)))
|
||||
(error (str "datalog aggregate (" op
|
||||
"): aggregation variable " agg-var
|
||||
" does not appear in the goal " goal
|
||||
" — without it every match contributes the same "
|
||||
"(unbound) value and the result is meaningless")))
|
||||
(else
|
||||
(let ((vals (list)))
|
||||
(do
|
||||
|
||||
Reference in New Issue
Block a user