Skip to content

Commit

Permalink
Make third argument of foreach tail-recursive.
Browse files Browse the repository at this point in the history
  • Loading branch information
01mf02 committed Nov 12, 2024
1 parent 2425052 commit 98d6f35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jaq-core/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
6 changes: 6 additions & 0 deletions jaq-core/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand Down

0 comments on commit 98d6f35

Please sign in to comment.