mutually-recursive types and an old puzzle
Arnaud Charlet
charlet@ACT-Europe.FR
Wed Jun 30 07:35:00 GMT 2004
> 1) can this kind of thing be represented in Ada?
Yes, e.g:
procedure P is
type T;
type T is access function (Input : Integer) return T;
function State_0 (Input : Integer) return T;
function State_1 (Input : Integer) return T;
function State_0 (Input : Integer) return T is
begin
if Input /= 0 then
return State_1'Access;
else
return State_0'Access;
end if;
end State_0;
function State_1 (Input : Integer) return T is
begin
if Input /= 0 then
return State_0'Access;
else
return State_1'Access;
end if;
end State_1;
Input : Integer;
State : T := State_0'Access;
begin
loop
Input := Read_Next_Input;
State := State (Input);
end loop;
end P;
More information about the Gcc
mailing list