What is tail call optimization?

前端 未结 10 1275
一整个雨季
一整个雨季 2020-11-21 06:36

Very simply, what is tail-call optimization?

More specifically, what are some small code snippets where it could be applied, and where not, with an explanation of wh

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 07:17

    Look here:

    http://tratt.net/laurie/tech_articles/articles/tail_call_optimization

    As you probably know, recursive function calls can wreak havoc on a stack; it is easy to quickly run out of stack space. Tail call optimization is way by which you can create a recursive style algorithm that uses constant stack space, therefore it does not grow and grow and you get stack errors.

提交回复
热议问题