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
Post a Comment