03 Recursion
03 Recursion
Definitions I
A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list consists of:
An open parenthesis, "(" Zero or more atoms or lists, and A close parenthesis, ")"
Definitions II
Indirect recursion is when a thing is defined in terms of other things, but those other things are defined in terms of the first thing Example: A list is:
An open parenthesis, Zero or more S-expressions, and A close parenthesis
Understanding recursion
The usual way to teach recursion is to trace through a recursion, seeing what it does at each level This may be a good way to understand how recursion works... ...but it's a terrible way to try to use recursion There is a better way
Combine the results of the recursion and the extra work into a complete solution Simpler means more like a base case
Each level of a recursive function has its own copy of these variables and parameters Changing them at one level does not change them at other levels One level can't interfere with another level
9
11
The End
12