comp.lang.ada
 help / color / mirror / Atom feed
* Zoo question
@ 1996-08-12  0:00 Ken Garlington
  1996-08-12  0:00 ` Chris Morgan
                   ` (4 more replies)
  0 siblings, 5 replies; 34+ messages in thread
From: Ken Garlington @ 1996-08-12  0:00 UTC (permalink / raw)



Here's a little brain teaser we received recently. Assuming no typos or 
other obvious syntax errors, will the Fill procedure work in Ada 83?

package Zoo is

  type Animal_ID is range 1 .. 5; -- yes, an enumeration type might be
 	                                -- better, but it spoils the example!

  subtype Cage_ID is Positive range 1 .. 12;

  type Cage_Row is array (Cage_ID) of Animal_ID;

  -- Fill fills a row of cages with various animals, in sequential order
  -- with alternating animals
  procedure Fill ( Cages : in out Cage_Row );

end Zoo;

package body Zoo is

  procedure Fill ( Cages : in out Cage_Row ) is
    Next_Animal : Animal_ID := Animal_ID'First;
  begin -- Fill
    for Cage in Cages'Range loop

      Cages(Cage) := Next_Animal;

      Get_Next_Animal: begin -- look carefully at this code!
        Next_Animal := Animal_ID'Succ(Next_Animal);
      exception
        when others => Next_Animal := Animal_ID'First;
      end Get_Next_Animal;

    end loop;
  end Fill;

end Zoo;




^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~1996-08-25  0:00 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-12  0:00 Zoo question Ken Garlington
1996-08-12  0:00 ` Chris Morgan
1996-08-13  0:00   ` Ken Garlington
1996-08-13  0:00 ` Ted Dennison
1996-08-14  0:00   ` Ken Garlington
1996-08-14  0:00     ` Ted Dennison
1996-08-15  0:00       ` Robert A Duff
1996-08-15  0:00       ` Ken Garlington
1996-08-18  0:00         ` Robert Dewar
1996-08-19  0:00           ` Ted Dennison
1996-08-19  0:00             ` Mark A Biggar
1996-08-20  0:00             ` Robert Dewar
1996-08-15  0:00     ` Robert Dewar
1996-08-15  0:00       ` Bob Gilbert
1996-08-19  0:00         ` Ted Dennison
1996-08-16  0:00       ` Ken Garlington
1996-08-19  0:00       ` Ted Dennison
1996-08-15  0:00   ` Keith Thompson
1996-08-14  0:00 ` Bob Gilbert
1996-08-14  0:00   ` Ted Dennison
1996-08-14  0:00     ` Bob Gilbert
1996-08-14  0:00       ` Ted Dennison
1996-08-14  0:00         ` Bob Gilbert
1996-08-14  0:00           ` Ken Garlington
1996-08-15  0:00             ` Robert A Duff
1996-08-16  0:00             ` Bob Gilbert
1996-08-19  0:00               ` Ted Dennison
1996-08-25  0:00                 ` Robert Dewar
1996-08-15  0:00           ` Robert I. Eachus
1996-08-14  0:00 ` Paul Hussein
1996-08-15  0:00 ` John Herro
1996-08-16  0:00   ` Robert Dewar
1996-08-18  0:00     ` John Herro
1996-08-19  0:00       ` Ken Garlington

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox