The recipe for designing functions on mutually referential data definitions generalizes that for self-referential data. Indeed, it offers only two pieces of additional advice. First, we must create several templates simultaneously, one for each data definition. Second, we must annotate templates with self-references and CROSS-REFERENCES, that is, references among different templates. Here is a more detailed explanation of the differences:
In the above example, we needed two interrelated definitions:
The first one concerns parents and another one for list of children. The first (unconditionally) defines a parent in terms of symbols, numbers, and a list of children, that is, it contains a cross-reference to the second definition. This second definition is a conditional definition. Its first clause is simple; its second clause references both the definition for parents and list-of-children.
Here are the templates for our running example:
The fun-for-parent template is unconditional because the data definition for parents does not contain any clauses. It contains one cross-reference to the second template: to process the children field of a parent structure. By the same rules, fun-for-loc is conditional. The second cond-clause contains one self-reference, for the rest of the list, and one cross-reference for the first item of the list, which is a parent structure.
A comparison of the data definitions and the templates shows how analogous the two are. To emphasize the similarity in self-references and cross-references, the data definitions and templates have been annotated with arrows. It is easy to see how corresponding arrows have the same origin and destination in the two pictures.
The rest of this step proceeds as before. When we deal with other clauses
or functions, we remind ourselves what each expression in the template
computes, assuming that all functions already work as specified in
the contracts. Then we decide how to combine these pieces of data into a
final answer. As we do that, we must not forget the guidelines concerning
the composition of complex functions (sections
and
).
The figure is not yet translated into HTML.
Figure: Designing groups of functions for groups of data definitions
the essential steps; for others see figures
(pg.
),
(pg.
), and
(pg.
)