Search code examples
javac#clojuretail-call

Tail calling in Java and 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?


Solution

  • 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.