Formulating a template for self-referential data
Question Answer
Does the data definition distinguish among different subclasses of data? Your template needs as many cond clauses as subclasses that the data definition distinguishes.
How do the subclasses differ from each other? Use the differences to formulate a condition per clause.
Do any of the clauses deal with structured values? If so, add appropriate selector expressions to the clause.
Does the data definition use self-references? Formulate “natural recursions” for the template to represent the self-references of the data definition.
Does the data definition refer to another data definition? Contemplate the development of a separate template. See Structures In Lists in the book.
How to turn the template into a function definition
Question Answer
What are the answers for the non-recursive cond clauses? The examples should tell you which values you need here. If not, formulate appropriate examples and tests.
What do the selector expressions in the recursive clauses compute? The data definitions tell you what kind of data these expressions extract and the interpretations of the data definitions tell you what this data represents.
What do the natural recursions compute Use the purpose statement of the function to determine what the value of the recursion means not how it computes this answer. If the purpose statement doesn’t tell you the answer, improve the purpose statement.
How can you combine these values into the desired answer? If you are stuck here, arrange the examples from the third step in a table. Place the given input in the first column and the desired output in the last column. In the intermediate columns enter the values of the selector expressions and the natural recursion(s). Add examples until you see a pattern emerge that suggests a ``combining’’ function.