procedure
EXCHANGE(U, V : in out
ELEM) is
-- see example in 12.1
T : ELEM; -- the generic formal type
begin
T := U;
U := V;
V := T;
end
EXCHANGE;
function
SQUARING(X : ITEM) return
ITEM is
-- see example in 12.1
begin
return
X*X; -- the formal operator "*"
end
;
package body
ON_VECTORS is
-- see example in 12.1
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
; for
N in
A'RANGE loop
RESULT(N) := SUM(A(N), B(N + BIAS)); -- the formal
-- function SUM
end loop
;
return
RESULT;
end
; 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
;
end
;