我什么时候可以在Scala中编写一个非尾递归函数? [英] When would I write a non-tail recursive function in Scala?

查看:90
本文介绍了我什么时候可以在Scala中编写一个非尾递归函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于非尾递归调用使用像Java那样的堆栈框架,所以我认为你会非常谨慎地使用它,如果有的话。由于它是最重要的工具之一,这看起来严格限制。

何时可以使用非尾递归函数?此外,是否有计划在将来删除内存限制?

解决方案

,您正在使用的数据集永远不会变得非常庞大,并且性能不是您的应用的关键/热门路径。



另外,恕我直言,有时候算法的非尾递归版本的清晰度比尾递归版本更好。


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?

解决方案

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.

这篇关于我什么时候可以在Scala中编写一个非尾递归函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆