Chapter 8
Using Recursive Functions
IN THIS CHAPTER
Defining recursion and how it works
Using recursion to perform advanced tasks
Mixing recursion with functions
Understanding common recursion errors
Some people confuse recursion with a kind of looping. The two are completely different sorts of programming and wouldn’t even look the same if you could view them at a low level. In recursion, a function calls itself repetitively and keeps track of each call through stack entries, rather than an application state, until the condition used to determine the need to make the function call meets some requirement. At this point, the list of stack entries unwinds with the function passing the results of its part of the calculation to the caller until the stack is empty and the initiating function has the required output of the call. Although this sounds mind-numbingly complex, in practice, recursion is an extremely elegant method of solving certain computing problems and may be the only solution in some situations. This chapter introduces you to the basics of recursion using the two target ...
Get Functional Programming For Dummies now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.