Encyclopedia > Mutual recursion

  Article Content

Mutual recursion

Mutual recursion is a form of recursion where two mathematical or computational functions are defined in terms of each other.

For instance, consider two functions A(x) and B(x) defined as follows:

  A(x) = 1         (when x≤1)
  A(x) = B(x + 2)  (when x>1)

  B(x) = A(x - 3) + 4

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.



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
1904

... 1899 1900 1901 1902 1903 - 1904 - 1905 1906 1907 1908 1909 See also: 1904 in film 1904 in literature 1904 in music 1904 in sports Events: ...

 
 
 
This page was created in 24.5 ms