scala - Is 'def eat():Unit = sleep(); def sleep(): Unit = eat()' a tail recursive function? -


two functions:

def eat(): unit = sleep() def sleep(): unit = eat() 

both of them recursive functions, because called in body (indirectly), right?

but tail recursive functions?

both of them recursive functions, because called in body (indirectly), right?

yes, called mutual recursion.

but tail recursive functions?

yes, are, call return value of body. however, afaik scala compiler not optimise these while loops, self-recursive functions. see does scala support tail recursion optimization? details, , how use tailcalls? workaround.


Comments

Popular posts from this blog

javascript - How to diff two immutable objects -

c# - How can I have the VS Debugger break in the correct location for exceptions thrown in Async methods in a Console App? -

javascript - React.js: onClick function from child to parent -