Tail Recursion
释义 Definition
尾递归:一种递归形式,函数在返回前做的最后一件事就是调用自身(或另一个函数),并且不再对递归调用的结果进行额外计算。在支持尾调用优化的语言/编译器中,尾递归常可像循环一样运行,减少栈增长。也常见于术语 tail-recursive(尾递归的)。
发音 Pronunciation (IPA)
/tel rkrn/
/tel rkrn/
例句 Examples
The factorial function can be written using tail recursion.
阶乘函数可以用尾递归来写。
With tail recursion and tail-call optimization, the program avoids building up a deep call stack.
借助尾递归与尾调用优化,程序可以避免累积很深的调用栈。
词源 Etymology
tail 意为“尾部/末尾”,recursion 源自拉丁语 recurrere(“跑回去、返回”),在计算机领域指“函数自己调用自己”。“tail recursion”字面意思就是“发生在末尾的递归调用”,强调递归调用位于函数执行的最后位置。
相关词 Related Words
文学与经典作品 Literary Works
- *Structure and Interpretation of Computer Programs (SICP)*(《计算机程序的构造和解释》):讨论递归过程与迭代过程的关系,常以尾递归/迭代式写法对照讲解。
- The Little Schemer(《小小 Scheme 佬》/《小 Scheme 书》常见译名):以 Scheme 示例讲解递归风格编程,尾递归与“累加器”写法频繁出现。
- Programming Languages: Application and Interpretation:介绍语言实现与求值模型时,会涉及尾调用/尾递归及其优化意义。
- Compilers: Principles, Techniques, and Tools(《编译原理》“龙书”):在优化相关内容中常提到尾调用(与尾递归密切相关)的优化思想。