Sometimes have algorithms with multiple states
Example:
| p(x) = | p(x-1) + q(x/2) | {x>1} |
| 2 | {x<=1} | |
| q(x) = | q(x-3) * p(x-5) | {x>3} |
| x/3 | {x<=3} |
This involves two recursive functions
Ada requires that things must be declared before they can be used.
Code
-- first declare q, so p can refer to it
function q (x: in float) return float;
-- now define p. Full definition is possible
function p (x: in float) return float is
begin
if (x<=1) then
return 2;
end if;
return p(x-1) + q(x/2);
end p;
-- now provide full definition of q
function q(x: in float) return float is
begin
if (x<=3) then
return x/3;
end if;
return q(x-3) * p(x-5);
end q;