[plt-scheme] HTDP Exercise 9.5.7
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.