[Home] [Prev] [Next] [Index]
6.5 Function Subprograms
6.5 Function Subprograms
- 1
- A function is a subprogram that returns a value (the result of the function call). The specification of a function starts with the reserved word
function
, and the parameters, if any, must have the mode in (whether this mode is specified explicitly or implicitly). The statements of the function body (excluding statements of program units that are inner to the function body) must include one or more return statements specifying the returned value.
- 2
- The exception PROGRAM_ERROR is raised if a function body is left otherwise than by a return statement. This does not apply if the execution of the function is abandoned as a result of an exception.
- 3
- Example:
function
DOT_PRODUCT(LEFT, RIGHT : VECTOR) return
REAL is
SUM : REAL := 0.0;
begin
CHECK(LEFT'FIRST = RIGHT'FIRST and
LEFT'LAST = RIGHT'LAST);
for
J in
LEFT'RANGE loop
SUM := SUM + LEFT(J)*RIGHT(J);
end loop
;
return
SUM;
end
DOT_PRODUCT;
- 4
- References:

- exception 11

- formal parameter 6.1

- function 6.1

- function body 6.3

- function call 6.4

- function specification 6.1

- mode 6.1

- program_error exception 11.1

- raising of exceptions 11

- return statement 5.8

- statement 5
[Home] [Prev] [Next] [Index]
documentation@rational.com
Copyright © 1993-2000, Rational Software Corporation. All rights
reserved.