Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 8. Handlers > Recursive Handlers

8.7. Recursive Handlers

Not only can a handler call other handlers, but it can also call itself! When a handler does that, it is called a recursive handler. Recursion is often a suitable choice for problems that can be solved by applying the same solution to subsets of the problem. Examples might be in the evaluation of parenthesized expressions, processing the elements of a list, or enumerating the contents of a folder, which itself might contain subfolders.

Perhaps the most commonly used illustration of recursion is in the calculation of factorials. The factorial of a positive integer n, written n!, is the product of the integers from 1 through n, inclusive. So the factorial of 5, or 5!, is calculated like this:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial