sealed class List<T> { // ... // Compiler : Recursive call is not a tail call tailrec fun dropWhile1(p: (T) -> Boolean): List<T> = when (this) { is Nil -> this is Cons -> if (p(head)) tail.dropWhile1(p) else this } fun dropWhile2(p: (T) -> Boolean): List<T> { // Ok tailrec fun impl(acc: List<T>): List<T> = when (acc) { is Nil -> acc is Cons -> if (p(acc.head)) impl(acc.tail) else acc } return impl(this) } }


밑 dropWhile2 메소드 안에 구현 함수를 정의하고 여기에 tailrec을 다는건 잘 되는데

완전히 같은 로직을 메소드 dropWhile1처럼 메소드로 끌어올리고 tailrec 달면 tail call 없다고 워닝나옴

obj.func(args)랑 func(obj, args) (위의 예에서는 args를 캡쳐해 func(obj)지만) 사이에 꼬리재귀 최적화하는데 있어서 어떤 차이가 있는거임?