-- Package of simple Integer Input output routines. with Text_io; package IIO is new Text_IO.Integer_io(integer); --need integer output ------------------------------------------------------------ with Text_IO; use text_IO; with IIO; procedure MAIN is begin IIO.put( 10#16# ); --? _________________ IIO.put( 2E3 ); --? _________________ IIO.put( 2#1#E4 ); --? _________________ IIO.put( 1, BASE=>16 ); --? _________________ end; ------------------------------------------------------------ with Text_io, iio; procedure DOIT is I:INTEGER:=7; begin for I in 2..5 loop exit when I = 4; iio.Put (I); text_io.Put(", "); end loop; iio.Put(I); text_io.New_line; end; with Text_IO, IIO, CALENDAR; use CALENDAR; procedure LEAP_TEST is FEB:constant MONTH_NUMBER:=2; HOURS:constant DURATION:=3600.00; ONE_DAY:constant DURATION:= 24*HOURS; Tab:constant CHARACTER :=ASCII.HT; NEXT_DAY:TIME; begin for YY in YEAR_NUMBER range 1992..1993 loop NEXT_DAY:=TIME_OF( YY, FEB, 28, 1*HOURS) + ONE_DAY; IIO.PUT( INTEGER( YEAR( NEXT_DAY ) )); Text_IO.PUT('/'); IIO.PUT( INTEGER( MONTH( NEXT_DAY ) )); Text_IO.PUT('/'); IIO.PUT( INTEGER( DAY( NEXT_DAY ) )); Text_IO.PUT(Tab); if YY = 1992 then Text_IO.Put_LINE(" = 1992/2/29 ?"); else Text_IO.Put_LINE(" = 1993/3/1 ?"); end if; end loop; end LEAP_TEST; ----------------------------------------------------------- -- Here is an example of a tasking: with Text_IO; use Text_IO; procedure SAMPLE is task T is entry SYNC; end T; task body T is begin Put('a'); Put('b'); accept SYNC do Put('c'); end SYNC; Put('d'); Put('e'); accept SYNC do New_Line; end SYNC; end T; begin Put('1'); T.SYNC; Put('2'); T.SYNC; -- end of line end SAMPLE; ---------------------------------------------------- -- The following package is needed in packages STUFF and NONSENSE below. package EXAMPLE is type A is record I:INTEGER; end record; type B is record I:INTEGER; end record; type C is ( I ); type D is array (C) of INTEGER; type E is (Quit, No, Yes); end EXAMPLE; -- Input/Output routines for data of types in EXAMPLE. with EXAMPLE; With Text_IO; package EIO is new Text_IO.ENUMERATION_IO(EXAMPLE.E); with TEXT_IO, EXAMPLE, EIO; procedure STUFF is VA:EXAMPLE.A:=(I=>1); VB:EXAMPLE.B:=(I=>1); VD:EXAMPLE.D:=(EXAMPLE.I=>1); I:INTEGER; begin -- errors have been commented out I:=I+VB.I; --? ______ --I:=VA+VB; --? ______ I:=VA.I+VB.I; --? ______ --I:=VA; --? ______ I:=VA.I; --? ______ --VB:=VA; --? ______ --I:=VD(I); --? ______ I:=VD(EXAMPLE.I); --? ______ --I:=VD.I; --? ______ VB:=EXAMPLE.B'(I=>VA.I);--? ______ VB.I:=VA.I; --? ______ end STUFF; -- Fill in the blanks below: with TEXT_IO, EXAMPLE, EIO; use EXAMPLE; procedure NONSENSE is begin TEXT_IO . Put( "Quit"); EIO . Put( Quit ); end NONSENSE; ------------------------------------------------------------------------------ generic type OBJECTS is private; procedure SWAP (X, Y: in out OBJECTS); procedure SWAP ( X,Y: in out Objects) is -- Afterwards X and Y's values are interchanged TEMP:OBJECTS:=X; begin X:=Y; Y:=TEMP; end SWAP; with SWAP; procedure SWAP_INT is new SWAP(OBJECTS=>INTEGER); generic type OBJECTS is private; with function "<" (LEFT, RIGHT: OBJECTS) return Boolean is <>; procedure ORDER (A, B: in out OBJECTS);-- Put into order so that A=B procedure SWITCHEROO is new SWAP(OBJECTS); begin if not B < A then SWITCHEROO (A,B); end if; end ORDER; -- Complete an instantiation that ORDERs two integers into increasing order, and one for the reverse oder. with ORDER; procedure UP_ORDER is new ORDER( OBJECTS=>INTEGER); with ORDER; procedure DOWN_ORDER is new ORDER(INTEGER, "<"); -- no need to use named parameters (and I had a problem....) --=================more silly generic stuff==================== generic type OBJECTS is private; with function "<" (LEFT, RIGHT: OBJECTS) return Boolean is <>; function MAX (A, B: OBJECTS) return OBJECTS; function MAX (A, B: OBJECTS) return OBJECTS is begin if B < A then return A; else return B; end if; end MAX; generic type INDEX is (<>); type ITEM is private; type VEC is array (INDEX range <>) of ITEM; with procedure DOTO(x:in out ITEM)is <>; procedure DO_TO_ALL(A:in out VEC) ; procedure DO_TO_ALL(A:in out VEC)is begin for I in A'range loop DOTO(A(I)); end loop; end DO_TO_ALL;