Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

tail recursion  RSS feed

 
Stephen Bloch
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any Java compilers out there that optimize tail-recursion into a loop using constant memory?

I'm running Java 1.4.1 on my Mac, and tried running the following three methods to see whether the compiler was making this optimization, and it wasn't: tailRecursiveSum crashed with a stack overflow around num=6445. I would have expected the recursiveSum method to stack-overflow, but if the compiler were optimizing tail-recursion (as is specified in Scheme), tailRecursiveSum would not stack-overflow, no matter how large a positive number I gave it.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried the -server option when running your test?

Googling for "java tail recursion" also gives a bunch of interesting hits...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!