[plt-scheme] critique of some code

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Dec 7 08:49:11 EST 2009

On Dec 7, 2009, at 7:54 AM, Prabhakar Ragde wrote:

> Matthias wrote:
> 
>> You can also assign it to those of your students who understand
>> accumulators (which is what many loops require, but we let students
>> loose on for/do/while/repeat/rinse/one-more-time with nothing but
>> intuition).
> 
> I would characterize the solution as structural recursion, since the accumulator is counting up towards a known bound. I know these categories are fuzzy at the edges, but my point is that I think this is a fair exercise in the "structural recursion on two values" part of an HtDP-based course. I often assign a similar question (using lists of symbols, and producing true/false instead of an index) at this point. --PR


Accumulator-based design doesn't stand by itself. It is always added to structural or generative recursion, meaning you have this grid: 

             plain | w/ accu 
 structural        |
 --------------------------
 generative        |

There are examples in the book for all four kinds of things. 

;; --- 

To recognize "structural w/ accumulator", ask yourself whether the conditional dispatch takes the changing argument (here the index into the string) into account. If so, you are looking at a multi-argument structural design. If not, you should look for the second symptom of accumulator design, namely, whether the second argument describes a fixed relationship between those parts of the first changing argument and its original value. A good designer writes down an accumulator statement for this. See my code. 

Hth -- Matthias



Posted on the users mailing list.