This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: mutually-recursive types and an old puzzle
- From: Arnaud Charlet <charlet at ACT-Europe dot FR>
- To: Joe Buck <Joe dot Buck at synopsys dot COM>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 30 Jun 2004 09:09:33 +0200
- Subject: Re: mutually-recursive types and an old puzzle
- References: <20040629160218.A1373@synopsys.com>
> 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;