Mutual recursion: Difference between revisions

Content deleted Content added
m + topic in text
LC~enwiki (talk | contribs)
fixed claim that this is "bad style"
Line 3:
For instance, consider two functions A(x) and B(x) defined as follows:
 
A(x,) x<= 1) = (''when x&le;1'')
A(x where x>1) = 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 programming language|Scheme]], [[ML]], and similar [[programming language|languages]]. In languages such as [[Prolog programming language|Prolog]], mutual recursion is almost unavoidable.
It is not obvious from inspection under what circumstances evaluating either of these functions will ever reach the non-recursive case,
and thus return an answer. This is common to most uses of mutual recursion, not just for contrived examples like the above. Therefore, in computer programming, mutually recursive functions are generally regarded as bad style.
 
Not all programming styles encourage mutual recursion. Some programmers avoid it because they find it confusing.