TCO is a runtime property, not a language property.
Anyway, you have clearly not been doing your research and its not my job to do it for you.
Bye.
TCO is a runtime property, not a language property.
Anyway, you have clearly not been doing your research and its not my job to do it for you.
Bye.
Edit: I am still seeking the legendary JVM implementation with TCO. I guess the argument is something like, oh well at some point in the future some JVM could conceivably have that feature, therefor it is wrong to say that Scala does not have it! Rather than writing code that assumes Scala is a complete joke of a functional language, one could simply write the code the natural way, verify that it compiles, and then wait until a JVM with TCO exists, so that it will stop crashing! In the mean time, one can enjoy the entertainment provided by Scala's inability to compile shift in an if statement without an else clause. Truly I am writing code exactly as I would if(it_was_synchronous) else { cpsunit }.
I feel as though you told me reset and shift, although you did not. So thanks for that!
scala> :paste
// Entering paste mode (ctrl-D to finish)
object TCO extends App {
def stackSize = Thread.currentThread.getStackTrace.length
def printStackSizeMessageOutside() =
println(s"$stackSize stackframes outside of the mutually recursive calls")
def printStackSizeMessageInside() =
println(s"$stackSize stackframes inside the mutually recursive calls")
def mutuallyRecursiveAdd1(a: Long, b: Long): Long =
if (b == 0) {
printStackSizeMessageInside()
a
} else
mutuallyRecursiveAdd2(a+1, b-1)
def mutuallyRecursiveAdd2(a: Long, b: Long): Long =
if (b == 0) {
printStackSizeMessageInside()
a
} else
mutuallyRecursiveAdd1(a+1, b-1)
printStackSizeMessageOutside()
mutuallyRecursiveAdd1(23, 10000000)
}
// Exiting paste mode, now interpreting.
defined object TCO
scala> TCO main null
We have 29 stackframes outside of the mutually recursive calls
We have 30 stackframes inside the mutually recursive calls 27 stackframes outside of the mutually recursive calls
java.lang.StackOverflowError
at TCO$.mutuallyRecursiveAdd2(<console>:22)
Oddly, your Thread.currentThread.getStackTrace.length seems to return strings like "We have 30". Mine is returning an Int over here.After a significant amount of effort (googling for stuff about scala, JVMs, and TCO mostly gets hits with people complaining about their code not working) I discovered something called Avian, which I can try out soon. I still think it is a bit weird to spend time engaging with a stranger who wants to know something very simple, but to expect the stranger to dig around for it for a few hours instead of telling him.
This way people who are lazy, whose interest is just strong enough to make ridiculous claims and complaints but don't actually care about the topic at hand, don't get things for free.
I protect my investment and everyone wins.