Mutual Recursion

In mathematics and computer science, mutual recursion is a form of recursion where two mathematical or computational functions are defined in terms of each other. It is sometimes called indirect recursion.

In mathematics, the Hofstadter Female and Male sequences are an example of a pair of integer sequences defined in a mutually recursive manner.

Mutual recursion is very common in the functional programming style, and is often used for programs written in LISP, Scheme, ML, and similar languages. In languages such as Prolog, mutual recursion is almost unavoidable. Some programming styles discourage mutual recursion, claiming that it can be confusing to distinguish the conditions which will return an answer from the conditions that would allow the code to run forever without producing an answer. Peter Norvig points to a design pattern which discourages the use entirely, stating:

If you have two mutually-recursive functions that both alter the state of an object, try to move almost all the functionality into just one of the functions. Otherwise you will probably end up duplicating code.

Read more about Mutual Recursion:  Example, Conversion To Direct Recursion

Famous quotes containing the word mutual:

    Marriage is an act of will that signifies and involves a mutual gift, which unites the spouses and binds them to their eventual souls, with whom they make up a sole family—a domestic church.
    John Paul II [Karol Wojtyla] (b. 1920)