elizarov

    elizarov

    2 years ago
    Running into StackOverflowError but have a lot of heap space to keep the state of your computation? Kotlin Coroutines can help https://medium.com/@elizarov/deep-recursion-with-coroutines-7c53e15993e3
    c

    Casey Brooks

    2 years ago
    This is awesome! I accidentally discovered this property some time ago when I made an infinitely-recursive coroutine and was surprised that it never ran out of memory. Since then, I’ve been interested in seeing how this property could help in writing recursive parsers with understandable error stacktraces, but didn’t know how I’d go about implementing one. This article looks to be pretty much exactly the key I needed for it!
    j

    janvladimirmostert

    2 years ago
    wouldn't
    tailrec
    have solved this depth problem as well or is this "problem" just to indicate how you would solve other deep recursive problems where tailrec is not an option?
    elizarov

    elizarov

    2 years ago
    The
    depth
    function is not tail-recursive and cannot be rewritten into a tail-recursive form unlike a similar function on lists, because depth makes two recursive calls. Even if one of them is transformed into a tail-call, then the other is still not a tail-call.
    j

    janvladimirmostert

    2 years ago
    ah, that makes sense