Designing Accumulator-Style Functions

Section~#secloss#40607> illustrated with two examples the need for accumulating extra knowledge. In some cases, the accumulation makes it easier to understand a function, in others it is necessary for the function to work properly. In both cases, however, we first chose one of the available design recipes, inspected the function, and then revised or fixed it. Put more generally, adding an <#67491#><#40608#>ACCUMULATOR<#40608#><#67491#>, that is, a parameter that accumulates knowledge, is something that we add to a function after we have designed a function, not before. The keys to the development of an accumulator-style function are:
  1. to recognize that the function benefits from, or needs, an accumulator;
  2. to understand what the accumulator represents.
The first two subsections address these two questions. Because the second one is a difficult topic, the third subsection illustrates how to formulate precise claims about accumulators. More concretely, in this section, we transform several standard recursive functions into functions that use auxiliary functions with accumulators.