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:
“Louise Bryant: Im sorry if you dont believe in mutual independence and free love and respect.
Eugene ONeill: Dont give me a lot of parlor socialism that you learned in the village. If you were mine, I wouldnt share you with anybody or anything. It would be just you and me. Youd be at the center of it all. You know it would feel a lot more like love than being left alone with your work.”
—Warren Beatty (b. 1937)