------------------------------------------------------------------------ -- -- -- NAME: The Four Seasons -- -- AUTHOR: Antonio Davivli -- -- DATE: 1983 -- -- -- ------------------------------------------------------------------------ -- C*T Interpreter features with TEXT_IO; -- We will use text_io to printout use TEXT_IO; -- our seasons. procedure FOUR_SEASONS is -- Define the SEASONS as an enumeration type. type SEASONS is (WINTER, SPRING, SUMMER, FALL); -- Create two SEASONS initialized to WINTER. THIS_SEASON,NEXT_SEASON : SEASONS:=WINTER; -- Define a generic CYCLIC_SUCC that will find the -- successor of an enumeration literal (for the -- instantiated enumeration type). generic -- generics type T is (<>); function CYCLIC_SUCC(X:T) return T; function CYCLIC_SUCC(X:T) return T is begin if X=T'LAST then return T'FIRST; -- Cycle on the boundary condition. else return T'SUCC(X); -- Otherwise take its successor. end if; end CYCLIC_SUCC; -- Instantiate cyclic_succ for seasons so that we -- can describe the rotation of the seasons. function SEASON_SUCC is new CYCLIC_SUCC(SEASONS); -- Print out a few examples of season rotation. begin for EXAMPLE in 1 .. 10 loop THIS_SEASON:=NEXT_SEASON; NEXT_SEASON:=SEASON_SUCC(NEXT_SEASON); PUT("The season after "); PUT(SEASONS'IMAGE(THIS_SEASON)); -- type attributes PUT(" is "); PUT_LINE(SEASONS'IMAGE(NEXT_SEASON)); end loop; end FOUR_SEASONS; ------------------------------------------------------------------------