From 98d6f35c87128ed70d784ac4e1255fa7e4a2e349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=C3=A4rber?= <01mf02@gmail.com> Date: Tue, 12 Nov 2024 08:26:29 +0100 Subject: [PATCH] Make third argument of `foreach` tail-recursive. --- jaq-core/src/compile.rs | 2 +- jaq-core/tests/tests.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/jaq-core/src/compile.rs b/jaq-core/src/compile.rs index 5abd04b82..2da6c52e5 100644 --- a/jaq-core/src/compile.rs +++ b/jaq-core/src/compile.rs @@ -672,7 +672,7 @@ impl<'s, F> Compiler<&'s str, F> { match (name, args.next(), args.next()) { ("reduce", None, None) => Term::Reduce(xs, pat, init, update), ("foreach", proj, None) => { - let proj = proj.map(|p| self.with_vars(&vars, |c| c.iterm(p))); + let proj = proj.map(|p| self.with_vars(&vars, |c| c.iterm_tr(p, tr))); Term::Foreach(xs, pat, init, update, proj) } _ => self.fail(name, Undefined::Filter(arity)), diff --git a/jaq-core/tests/tests.rs b/jaq-core/tests/tests.rs index 533598053..88429cdab 100644 --- a/jaq-core/tests/tests.rs +++ b/jaq-core/tests/tests.rs @@ -458,6 +458,12 @@ yields!( yields!(tailrec, "def f: if . > 0 then .-1 | f end; 100000 | f", 0); +yields!( + foreach_tailrec, + "def f: if . > 0 then foreach . as $x (.; .-1; f) end; 10000 | f", + 0 +); + yields!( comments, r#"