Mutual recursion: Difference between revisions
→{{header|CLU}}: Correct and clarify the Clu example. No special tricks are needed for mutual recursion, it's standard practice to "spec" the clu file before compiling it.
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(→{{header|CLU}}: Correct and clarify the Clu example. No special tricks are needed for mutual recursion, it's standard practice to "spec" the clu file before compiling it.) |
||
Line 1,049:
=={{header|CLU}}==
<syntaxhighlight lang="clu">%
% the clu file itself as a specfile. For a small program a common
% idiom is to spec and compile the same source file:
%
% pclu -spec mutrec.clu -clu mutrec.clu
%
F = proc (n: int) returns (int)▼
start_up = proc ()
if n=0 then return(1)▼
print_first_16("M", M)▼
end▼
if n=0 then return(0)▼
end▼
end M▼
% Print the first few values for F and M
Line 1,076 ⟶ 1,064:
po: stream := stream$primary_output()
stream$puts(po, name || ":")
for i: int in int$from_to(0, 15) do
end
stream$putl(po, "")
end print_first_16
return (1)
▲ print_first_16("M", M)
end start_up</syntaxhighlight>▼
return (n - M(F(n-1)))
▲ end
end F
return (0)
else
return (n - F(M(n-1)))
{{out}}
<pre>F: 1 1 2 2 3 3 4 5 5 6 6 7 8 8 9 9
|