This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: mutually-recursive types and an old puzzle


> 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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]