# How to call a recursive function without stackoverflow?

**URL:** <https://discourse.julialang.org/t/how-to-call-a-recursive-function-without-stackoverflow/95865>\
**Category:** New to Julia\
**Tags:** compilation, recursion\
**Created:** [March 10, 2023, 12:48pm UTC](https://discourse.julialang.org/t/how-to-call-a-recursive-function-without-stackoverflow/95865 "2023-03-10T12:48:00Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [March 11, 2023, 5:11pm UTC](https://discourse.julialang.org/t/how-to-call-a-recursive-function-without-stackoverflow/95865/11 "2023-03-11T17:11:41Z")

</div>

> [@uniment](#):
>
> Why not?

There have been numerous discussions on this topic in the past. See for example this one and the references therein:

> [@Does Julia have tail call optimization?](https://discourse.julialang.org/t/does-julia-have-tail-call-optimization/64101):
>
> does Julia have tail call optimization ? or does a recursive function always overflow regardless of if you are careful to construct it in that fashion ?

  

The following thread is also very interesting IMO, in that it discusses the topic from a different point-of-view:

> [@Tail-call optimization and function-barrier -based accumulation in loops](https://discourse.julialang.org/t/tail-call-optimization-and-function-barrier-based-accumulation-in-loops/25831/1):
>
> Tail-call optimization/elimination was brought up in several threads like [this one in discourse](https://discourse.julialang.org/t/recursive-call-vs-while-loop/7723) and [this one in GitHub](https://github.com/JuliaLang/julia/issues/4964). The main interest seems to be purely based on the nice-to-have performance benefit and the core devs seem to be open to the change while assigning very low priority because writing for/while-loop is more idiomatic in Julia. But I think there is another point of view related to function-barrier -based accumulation which makes me wonder if the tail-call optimization actually mak…

---

_[View the full topic](https://discourse.julialang.org/t/how-to-call-a-recursive-function-without-stackoverflow/95865)._
