Iterator operator: automatic temporary variables _index and _count changed with '__' and '_#' respectively. Note that, sinc '#' is not an identifier allowed char, '_#' requires himBHsnotation: -cover

This commit is contained in:
2026-05-02 15:06:12 +02:00
parent 3b2ef7927b
commit 2ebc52891c
4 changed files with 14 additions and 13 deletions
+4 -4
View File
@@ -43,8 +43,8 @@ func evalFilter(ctx kern.ExprContext, opTerm *term) (v any, err error) {
values := kern.NewListA()
for item, err = it.Next(); err == nil; item, err = it.Next() {
ctx.SetVar("_", item)
ctx.SetVar("_index", it.Index())
ctx.SetVar("_count", it.Count())
ctx.SetVar("__", it.Index())
ctx.SetVar("_#", it.Count())
if rightValue, err = opTerm.children[1].Compute(ctx); err == nil {
if success, valid := kern.ToBool(rightValue); valid {
if success {
@@ -54,8 +54,8 @@ func evalFilter(ctx kern.ExprContext, opTerm *term) (v any, err error) {
err = fmt.Errorf("filter expression must return a boolean or a castable to boolean, got %v [%T]", rightValue, rightValue)
}
}
ctx.DeleteVar("_count")
ctx.DeleteVar("_index")
ctx.DeleteVar("_#")
ctx.DeleteVar("__")
ctx.DeleteVar("_")
if err != nil {
break