From Paul’s description of the problem at hand, we are trying to find the odds of becoming the next mega-millionare. The following is the imperative solution provided by Paul using a variable to accumulate the odds at any given step in the process as the multiple of the previous value and the new expression result.
Paul presents the conversion of this code segment to a simple recursive function that will help us to find the value of by calling the function over and over with varying values defined within the function until a termination clause is reached. In this case the termination clause is when the variable n equals the value 0.
By using a technique known as Fixed Point Combinator, and specifically a Y-Combinator we will not on obtain the result but build recursion without using a named function. To begin, a Fixed Point Combinator is a special type of higher order function that has the unique transitive property that for any function F and value V, the value of the Y-Combinator function G when passed the parameter F will return the value V which is the same value as when V is passed to F. Lost? Lets look at this description as a the transitive function definition:
[code]F(G(F)) == G(F)[/code]
With this definition of a Y-Combinator, let us revise the original problem set using the code from the recursive definition. The most important part that we can take from the recursive definition is the conditional logic, in fact that is all we will be taking. The Y-Combinator version of this looks like this: