When would I write a non-tail recursive function in Scala?

浪子不回头ぞ 提交于 2019-12-25 02:30:01

问题


Since non-tail recursion calls use stack frames like Java does, I'd think you'd be using it very sparingly, if at all. This seems however severely restrictive given it's one of the most important tools.

When can I use non-tail recursion functions? Also, are there plans to remove the memory restriction in the future?


回答1:


In the same situations where it would be safe in Java, where the dataset you are working with never grows huge and the performance isn't critical/hot path of your app.

Also, IMHO, there are times when the clarity of non tail recursion version of an algorithm is way better than the tail recursive version.



来源:https://stackoverflow.com/questions/24619987/when-would-i-write-a-non-tail-recursive-function-in-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!