If a line processes compound data, we enrich the template with appropriate selector expressions. Using the conditional template, we split the task into simpler tasks. Specifically, we can focus on each cond -line separately, simply considering the question what is the output if we are given this kind of input. All other cases are ignored as we work out one particular clause. Suppose we want to define a function that computes the perimeter of a shape.
Figure summarizes the development of our running example.
If we do not understand what kind of data a function consumes, we cannot design it and organize it properly. If, however, we do understand the structure of the data definition and organize our template properly, it is easy to modify or to extend a function. For example, if we add new information to the representation of a circle , then only those cond -clauses related to circles may require changes. Similarly, if we add a new kind of shape to our data definition, say, rectangles, we must add new cond -clauses to our functions. Develop structure and data definitions for a collection of zoo animals.