Lady Ada

Ada '83 Language Reference Manual

Copyright 1980, 1982, 1983 owned by the United States Government. Direct reproduction and usage requests to the Ada Information Clearinghouse.

6.5. Function Subprograms


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.

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.


    function DOT_PRODUCT(LEFT, RIGHT : VECTOR) return REAL is
       SUM : REAL := 0.0;
       for J in LEFT'RANGE loop
          SUM := SUM + LEFT(J)*RIGHT(J);
       end loop;
       return SUM;
    end DOT_PRODUCT; 

References: exception, formal parameter, function, function body, function call, function specification, mode, program_error exception, raising of exceptions, return statement, statement.

Rationale references: 8.4 Function Subprograms

Style Guide references: 2.1.1 Horizontal Spacing, 3.2.4 Program Unit Names, 4.1.3 Functions, 4.3.1 Using Exceptions to Help Define an Abstraction, 5.9.6 Initialization


[Ada Information Clearinghouse]

Address any questions or comments to