Mutual recursion: Difference between revisions

Content added Content deleted
(Add APL)
(Add CLU)
Line 1,025:
1
(- n (M (F (dec n))))))</lang>
 
=={{header|CLU}}==
<lang clu>% 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</lang>
{{out}}
<pre>F: 1 1 2 2 3 3 4 5 5 6 6 7 8 8 9 9
M: 0 0 1 2 2 3 4 4 5 6 6 7 7 8 9 9</pre>
 
=={{header|CoffeeScript}}==