Two functions are said to be mutually recursive if the first calls the second,
and in turn the second calls the first.

Write two mutually recursive functions that compute members of the Hofstadter Female and Male sequences defined as:










F
(
0
)



=
1
 
;
 
M
(
0
)
=
0




F
(
n
)



=
n
−
M
(
F
(
n
−
1
)
)
,

n
>
0




M
(
n
)



=
n
−
F
(
M
(
n
−
1
)
)
,

n
>
0.






{\displaystyle {\begin{aligned}F(0)&=1\ ;\ M(0)=0\\F(n)&=n-M(F(n-1)),\quad n>0\\M(n)&=n-F(M(n-1)),\quad n>0.\end{aligned}}}





(If a language does not allow for a solution using mutually recursive functions
then state this rather than give a solution by other means).




% At the top level, definitions can only see the definitions above.
% But if we put F and M in a cluster, they can see each other.
mutrec = cluster is F, M
    rep = null 
 
    F = proc (n: int) returns (int)
        if n=0 then return(1)
        else return(n - M(F(n-1)))
        end
    end F
 
    M = proc (n: int) returns (int)
        if n=0 then return(0)
        else return(n - F(M(n-1)))
        end
    end M
end mutrec 
 
% If we absolutely _must_ have them defined at the top level,
% we can then just take them out of the cluster.
F = mutrec$F
M = mutrec$M
 
% Print the first few values for F and M
print_first_16 = proc (name: string, fn: proctype (int) returns (int))
    po: stream := stream$primary_output()
    stream$puts(po, name || ":")
    for i: int in int$from_to(0,15) do
        stream$puts(po, " " || int$unparse(fn(i)))
    end
    stream$putl(po, "")
end print_first_16
 
start_up = proc ()
    print_first_16("F", F)
    print_first_16("M", M)
end start_up