What is tail recursion?

前端 未结 28 3717
一个人的身影
一个人的身影 2020-11-21 05:03

Whilst starting to learn lisp, I\'ve come across the term tail-recursive. What does it mean exactly?

28条回答
  •  旧时难觅i
    2020-11-21 05:09

    There are two basic kinds of recursions: head recursion and tail recursion.

    In head recursion, a function makes its recursive call and then performs some more calculations, maybe using the result of the recursive call, for example.

    In a tail recursive function, all calculations happen first and the recursive call is the last thing that happens.

    Taken from this super awesome post. Please consider reading it.

提交回复
热议问题