Mutual recursion: Difference between revisions

m
Line 863:
 
=={{header|Nemerle}}==
There's probably some improvement that can be made here, but at least it illustrates the syntax for mutual recursion. It seems that the mutually recursive functions '''must''' be enclosed in an outer function.
<lang Nemerle>using System;
using System.Console;
Line 869 ⟶ 868:
module Hofstadter
{
HofstadterF(mn : int, start : string) : int
{
def|0 F(n=> : int)1
{|_ => n - M(F(n - 1))
|0 => 1}
|_ => n - M(F(n - 1))
M(n : int) : }int
{
and M(n : int)
{|0 => 0
|_ => n - |0F(M(n =>- 01))
|_ => n - F(M(n - 1))
}
match(start)
{
|"F" => F(m)
|"M" => M(m)
}
}
Main() : void
{
foreach (n in [0 .. 20]) Write("{0} ", HofstadterF(n, "F"));
WriteLine();
foreach (n in [0 .. 20]) Write("{0} ", HofstadterM(n, "M"));
}
}</lang>