Mutual recursion: Difference between revisions
Content added Content deleted
(Added BASIC) |
(added standard ml) |
||
Line 609:
check for zero
</lang>
=={{header|Standard ML}}==
<lang sml>fun f 0 = 1
| f n = n - m (f (n-1))
and m 0 = 0
| m n = n - f (m (n-1))
;</lang>
The <code>'''fun'''</code> construct creates recursive functions, and the <code>'''and'''</code> allows a group of functions to call each other. The above is just a shortcut for the following:
<lang sml>val rec f = fn 0 => 1
| n => n - m (f (n-1))
and m = fn 0 => 0
| n => n - f (m (n-1))
;</lang>
which indicates that the functions call themselves (<code>'''rec'''</code>) and each other (<code>'''and'''</code>).
=={{header|Tcl}}==
|