https://kotlinlang.org logo
#coroutines
Title
# coroutines
e

elizarov

08/20/2018, 7:39 AM
@louiscad Coroutines don’t immediately allow recursive methods without StackOverflow, but you can use Kotlin coroutines machinery to transform any recursive algorithm that uses call stack into one that uses heap to maintain its stack, thus supporting much deeper recursion without running out of resources. I wrote a prototype at one point. See this gist: https://gist.github.com/elizarov/d715c9564288c2635bb55687e7341717
👍 2
l

louiscad

08/20/2018, 7:40 AM
That's what I thought, since a
suspend fun
can suspend... or return, in which case it adds up to the stack
e

elizarov

08/20/2018, 7:40 AM
As an example (included in this gist), we can write a recursive function in direct style that computes a sum over a tree without running into StackOverflow.
l

louiscad

08/20/2018, 7:41 AM
without running into StackOverflow.
Unless you got a question 😅
🙂 1
stackoverflow 3
🧌 1
4 Views