<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Forget about the term generative recursion for a second.<br><br>I've coined a phrase that for me encapsulates much of the approach of the Design Recipe - I call it Delta Programming.<br><br>Why - well you have a result you would like, you have your input and you have in your template a bunch of expressions - lets call them partial results - which are derived from your inputs.<br><br>Assuming you have listed those partial results, often times the problem reduces to picking the expression that yields the partial result nearest to your goal and working out the adjustments needed to give you your answer. So instead of programming from a blank slate, you are programming what needs to change (i.e the delta), given the partial results.<br><br>So you came up with a test<font style="" class="fixed_width" face="Courier, Monospaced"><br><br>(tabulate-div 20) should equal (list 1 2 4 5 10 20) </font><br><br>Lets start with what you know. <br>Previously you have been given a template for numeric recursion<br><br>(define (tabulate-div n)<br> (cond<br> [(zero? n) ......]<br> [else .........n..........................................<br> ........(sub1 n)................................<br> ........(tabulate-div (sub1 n))........]))<br><br>the meaning of n and (sub1 n) is apparent, but what does (tabulate-div (sub1 n)) mean.<br><br>Use your example. If (tabulate-div 20) means give me all the divisors of 20 what does (tabulate-div (sub1 20)) give.<br>Well thats (tabulate-div 19). What does it mean and how is it relevant to what I am trying to achieve.<br><br>Lets say we figure out a simple recursive call isn't going to help us here, what else can we do.<br><br>Well some kind of recursive call is obviously necessary (after all this is the section on generative recursion).<br>Lets look at (tabulate-div (sub1 n)) again but think of it as (tabulate-div (function-that-generates-the-next-problem)) and <br>we have just tried it with function-that-generates-the-next-problem set to (sub1 n). <br>Did it work?<br><br>Really we want (tabulate-div (function-that-generates-the-next-problem)) to give us (list 2 4 5 10 20) and to combine that answer <br>with the answer to the 1st problem which is 1. <br><br>So the solution begins to look something like <br><br> (combine (solution involving n)<br> (tabulate-div (function-that-generates-next-problem))<br><br>Lets take your solution to the 1st problem - you generated 1 by dividing n by n (i.e 20/20) and your idea was to divide each successive problem by n.<br><br>Hmmm? That suggests that on each iteration you need to have the original value of n available - how are you going to achieve that.<br><br>Lets say you figure that out, the next number that features in your solution is 2 and you said you were going to do divisions.<br><br>Well if n is going to feature in those divisions, we either have x/n = 2 or n/x = 2. <br><br>Right what is n going to be? <br>Given we have figured n, what expression are we going to use to get our 2nd expression - x/n or n/x.<br>Given we have chosen between these expressions (function-that-generates-next-problem) has to be something that will successively generate x's to give us the (2 4 5 10 20).<br><br>Is every x we generate going to contribute to our answer? <br>If not how do we decide which x's to keep and which not to?<br><br>Try thinking along those lines and see how you get on.<br><br><br><br><br><br><br><br><br><br><br><br>                                            </body>
</html>