[plt-scheme] HTDP Exercise 9.5.7

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Apr 13 12:56:49 EDT 2009

Thanks for yelling.

I answered in private and it is NOT a violation of design, in the  
spirit of HtDP, but a good example of

  -- figure out the tasks involved
  -- design one function per task.

It just happens to be the first exercise that throws students back to  
this rule introduce earlier in the book and not exercised.

-- Matthias





On Apr 13, 2009, at 12:55 PM, Todd O'Bryan wrote:

> I just got yelled at for posting complete code to one of the book
> problems, so I'll yell this time: try to avoid posting complete
> answers to book exercises--instead post enough info so people know
> what you're asking and you can send code to individuals rather than
> the whole list if needed.
>
> That said, yes, you're on the right track. I make a big deal of this
> problem with my classes and say, "I've lied to you. Here's a function
> that doesn't follow the template. What could I have been thinking?!!!"
> and then we talk about the fact that using helper functions that
> follow the template is really just another way of using the template,
> so my reputation as a trustworthy teacher remains unscathed.
>
> Todd
>
> On Mon, Apr 13, 2009 at 12:12 PM, S Brown <ontheheap at gmail.com> wrote:
>> I'm working my way through HTDP and I have a question regarding
>> Exercise 9.5.7. The exercise asks you to define the function average-
>> price, which takes as it's input a list of prices, and gives as  
>> output
>> the average of the prices in the list. I came up with  the following
>> solution:
>>
>> I came to this solution after not being able to figure out how to  
>> keep
>> track of the sum of the items and also the number of items at the  
>> same
>> time. So my concern/question is, is my solution acceptable, or should
>> I keep trying to figure out how to keep track of both values (sum and
>> number of items) without resulting to helper-functions such as sum-
>> list and num-items? Thanks.
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.