|
If you're working furiously to finish the assignment, skip this message for now, and read it later. This is some fairly advanced stuff, going beyond the material really needed for the assignment, for those who are interested in following higher-order programming even farther. Although the full solution for nested lists in problem #2 is feasible, it's not terribly elegant. That's why I will be thoroughly satisfied with the unnested solution. There is an even more general mechanism for recursion on trees, which provides an elegant way of defining
The extra argument, context, lets the recursively defined function take into account whether it's working on a left or right subtree, or the root. I haven't debugged this at all, but I think it's essentially right. If my old reduce-tree is the mother of all higher-order functions to produce operations on binary trees, perhaps reduce-tree-with-context is the grandmother.
Then, there's the great-...-grandmother. You can beef the definition up to provide each recursive call to Mike O'D. |
to: