(5) procedure Exchange(U, V : in out Elem) is -- see 12.1 T : Elem; -- the generic formal type begin T := U; U := V; V := T; end Exchange;
(7) function Squaring(X : Item) return Item is -- see 12.1 begin return X*X; -- the formal operator "*" end Squaring;
(9) package body On_Vectors is -- see 12.1 (10) function Sum(A, B : Vector) return Vector is Result : Vector(A'Range); -- the formal type Vector Bias : constant Integer := B'First - A'First; begin if A'Length /= B'Length then raise Length_Error; end if; (11) for N in A'Range loop Result(N) := Sum(A(N), B(N + Bias)); -- the formal function Sum end loop; return Result; end Sum; (12) function Sigma(A : Vector) return Item is Total : Item := A(A'First); -- the formal type Item begin for N in A'First + 1 .. A'Last loop Total := Sum(Total, A(N)); -- the formal function Sum end loop; return Total; end Sigma; end On_Vectors;
-- Email comments, additions, corrections, gripes, kudos, etc. to:
Magnus Kempe -- Magnus.Kempe@di.epfl.ch