Two functions:
def eat(): Unit = sleep()
def sleep(): Unit = eat()
Both of them are recursive functions, because they called themselves in the body (indirectly), right?
But are they tail recursive functions?
Two functions:
def eat(): Unit = sleep()
def sleep(): Unit = eat()
Both of them are recursive functions, because they called themselves in the body (indirectly), right?
But are they tail recursive functions?
Both of them are recursive functions, because they called themselves in the body (indirectly), right?
Yes, this is called mutual recursion.
But are they tail recursive functions?
Yes, they are, as the call is the return value of the body. However, afaik the Scala compiler does not optimise these into while
loops, it only does so for self-recursive functions. See Does Scala support tail recursion optimization? for details, and How to use TailCalls? for a workaround.