[plt-scheme] HtDP: Another question on 10.1.9

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Sat Sep 20 10:13:42 EDT 2008

On Fri, Sep 19, 2008 at 8:44 PM, Grant Rettke <grettke at acm.org> wrote:
> On Fri, Sep 19, 2008 at 7:29 PM, Carl Eastlund <cce at ccs.neu.edu> wrote:
>> On Fri, Sep 19, 2008 at 10:51 AM, Grant Rettke <grettke at acm.org> wrote:
>>>
>>> I followed (abused?) a recipe by using cond and having the first
>>> clause handle any amount under 100. It looks like this:
>>>
>>> (cond
>>>    [(< n 100) <cents part goes here>]
>>>    [else (cons <dollar amount and natural recusion occur here>)])
>>
>> Natural recursion?  What's so natural about it?
>
> You don't need to do all of the work at once, you handle the part that
> you need and let the function do the rest of it. In this case, the
> rest is everything under 100. Is this a valid approach if there is
> only one recursive step?
>
> Or were you just giving me a hard time with your reply?

Let me put it another way -- what's so recursion about it?  To be less
cryptic, if you read your purpose statement, and apply it to the
recursive call, does it make sense?  Are you really solving a smaller
instance of the same problem, or are you just solving a smaller
problem?  The former is recursion; the latter is not (and suggests
either inlining or a helper function).

-- 
Carl Eastlund


Posted on the users mailing list.