# Best data structure for recursive functions?

**URL:** https://discourse.julialang.org/t/best-data-structure-for-recursive-functions/112289
**Category:** New to Julia
**Tags:** question
**Created:** [March 29, 2024, 1:12pm UTC](https://discourse.julialang.org/t/best-data-structure-for-recursive-functions/112289 "2024-03-29T13:12:44Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![phantom](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@phantom](https://discourse.julialang.org/u/phantom)
#### Post date: [March 29, 2024, 10:15pm UTC](https://discourse.julialang.org/t/best-data-structure-for-recursive-functions/112289/3 "2024-03-29T22:15:10Z")

</div>

Wow thanks so much for this and your other posts on recursion.

Originally I used `@async` and `Ref` to break the loop with an external command. However the [warning](https://docs.julialang.org/en/v1/base/parallel/#Base.@async) in the docs encouraged the use of @spawn over @async. Am I correct in understanding that in cases involving the parallel mutation of arrays `@async` is still preferable over `@spawn` becuase it disables the migration of the _parent_ task across worker threads?

With a while loop it seems like breaking the loop with an external command becomes more periphrastic than using tail end recursion. Something like

```julia
function main(testpop, cont = Ref(true))
    @async while all(!isempty,testpop) && cont[] 
        for group in testpop
            condition = second(now())/10    
            @async for people in group
                cont [] || break      
                if condition <= rand(1:12)  
                    break 
                else   
                    fun1(people)
                    popfirst!(group)
                end
            end
            return(cont)
        end 
    end
    return(cont) 
end 

```

When you mention in this [post](https://discourse.julialang.org/t/recursive-call-vs-while-loop/7723/18) that

> [@Recursive call vs while loop](https://discourse.julialang.org/t/recursive-call-vs-while-loop/7723/18):
>
> If you have a tail-recursive algorithm, on the other hand, recursion is usually uninteresting and has no particular advantages; you might as well rewrite it into the equivalent loop.

Did you mean that there are meaningful disadvantages to tail end recursion in julia? Or is it just bad practice in general?

---

_[View the full topic](https://discourse.julialang.org/t/best-data-structure-for-recursive-functions/112289)._
