What you are looking for is tail call elimination (also called as tail call optimization or tail recursion optimization). There have been a number of threads on the subject here, e.g. this one. According to this discussion, “Julia doesn’t have tco currently, and is fairly unlikely to add it.” That being said, a macro is being considered on Github.
HanD
2
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| Tail-call recursion | 41 | 4547 | December 15, 2022 | |
| Recursive call vs while loop | 21 | 12460 | April 12, 2022 | |
| Yet another TCO thread | 5 | 2452 | May 25, 2022 | |
| Does Julia have tail call optimization? | 4 | 4462 | July 5, 2021 | |
| How to call a recursive function without stackoverflow? | 10 | 1243 | March 11, 2023 |