Java 和 C# 中的尾部调用?
我正在阅读有关 Clojure 的内容,发现有关 Java 在当前版本中不支持尾部调用的讨论,并且人们抛出异常来模拟 JVM 中的尾部调用,无论如何,听起来人们正在做一些疯狂的事情。 所以这让我想知道 C# 的尾部调用,同样的问题吗?
I was reading about Clojure and found a discussion about Java not supporting tail calls, in the current version, and that people were throwing exceptions to simulate tail calling in the JVM, anyways it sounds like people are doing some crazy stuff out there. So this got me wondering about C#'s tail calling, same issues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CLR 代码在某些情况下会尾部调用,但在其他情况下不会 - 这取决于 JIT。
请参阅 David Broman 的博客文章 和 Shri Borde 也是一个。
C# 编译器当前不会发出尾部调用 IL,但有时 JIT 无论如何都会执行此操作。
CLR code will tail call in some cases but not others - it depends on the JIT.
See David Broman's blog entry and Shri Borde's one too.
The C# compiler doesn't currently emit tail call IL, but sometimes the JIT will do it anyway.
在某些情况下,尾递归在 JVM 上是可能的。 例如,Scala 要求有效地实现基本尾递归(请参阅此博客文章,查找 语言琐事 #8,我刚才能找到的唯一引用)。 人们正在谈论和研究如何添加更多支持,以及 Invoke Dynamic 和其他专门针对非 Java 语言的功能。
The Java Posse 上也经常讨论此类问题。
是的,我知道这完全不是你问题的答案......
Tail recursion is possible on the JVM in certain cases. For example, Scala asks for an efficient implementation of basic tail recursion (see this blog post, look for Language Trivia #8, only quote I could find just now). There is talk and research about adding more support, in the same effort as Invoke Dynamic and other features specialized for non-Java languages.
There is also quite often talks about those kind of issues on The Java Posse.
And yes, I know that this is totally not an answer to your question ...