Content deleted Content added
m HTTP → HTTPS for Carnegie Mellon CS, replaced: http://www.cs.cmu.edu/ → https://www.cs.cmu.edu/ (3) |
→Basic examples: type hint |
||
Line 48:
As a more general class of examples, an algorithm on a tree can be decomposed into its behavior on a value and its behavior on children, and can be split up into two mutually recursive functions, one specifying the behavior on a tree, calling the forest function for the forest of children, and one specifying the behavior on a forest, calling the tree function for the tree in the forest. In Python:
<source lang="python">
def f_tree(tree) -> None:
f_value(tree.value)
f_forest(tree.children)
def f_forest(forest) -> None:
for tree in forest:
f_tree(tree)
|