Scala can only do it by transforming the recursive call into a jump at compile time - hence the single method restriction.
We *could* do better in theory, but only at the unacceptable expense of compatibility with other languages on the platform. If the JVM did it, however, then this wouldn't be a problem. You may also want to point your colleague in the direction of every improvement that John Rose has ever suggested. Fixnum's would be a pretty beneficial addition as well! On Jul 20, 2012 9:56 PM, "clay" <[email protected]> wrote: > Wow, I didn't realize Scala had already completed this. If I may ask, what > is the advantage of JVM level support? > > One of my Scala expert colleagues said this was the only feature he could > think of in addition to Jigsaw that was needed at the JVM level. > > On Friday, July 20, 2012 3:39:24 PM UTC-5, KWright wrote: >> >> Scala has already been doing it for quite some time now, but just within >> a single method. >> >> It will happen by default where possible. If you want to be certain then >> use the @tailrec annotation on your method, which will force the compiler >> to emit an exception if it can't be done. >> >> For anything "bigger", such as tail recursing across two or more methods, >> you'll need something like the trampoline functionality that scalaz >> provides. >> > -- > You received this message because you are subscribed to the Google Groups > "Java Posse" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/javaposse/-/cdKdk3n1vu0J. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > -- You received this message because you are subscribed to the Google Groups "Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
