递归
- 递归的定义
- 递归的好处
- 互递归
- 递归的弊端
- 尾调用
- 递归的优化
递归的定义
递归就是一个函数在其内部调用它自己,同时有一个条件来终止这个递归的循环调用。
递归的好处
递归可以使我们的代码更加的接近声明式的代码,可读性会更加好一些。
The most commonly cited reason that recursion fits the spirit of FP is because it trades (much of)
the explicit tracking of state with implicit state on the call stack. Typically, recursion is most useful
when the problem requires conditional branching and back-tracking, and managing that kind
of state in a purely iterative environment can be quite tricky; at a minimum, the code is highly
imperative and harder to read and verify. But tracking each level of branching as its own scope
on the call stack often significantly cleans up the readability of the code.
互递归
互递归(Mutual Rescursion)就是当两个或多个函数在递归循环中相互调用时,这称为互递归。
exa