Chapter 8. Procedures

Table of Contents
8.1. Answer Specification
8.2. Procedure Heading
8.3. Parameter Specification
8.4. The Procedure Body

A procedure is a body of program, written out once only, named with an identifier, and available for execution anywhere within the scope of the identifier. There are three methods of communication between a procedure and its program environment.

  1. The body may use formal parameters, of types specified in the heading of the procedure declaration and represented by identifiers local to the body. When the procedure is called, the formal parameters are replaced by actual parameters, in one-to-one correspondence.

  2. The body may use non-local identifiers whose scopes embrace the body. Such identifiers are also accessible outside the procedure.

  3. An answer statement within the procedure body may compute a single value for the procedure, making its call suitable for use as a function in an expression. A procedure which possesses a value is known as a typed procedure.

The syntax for a procedure declaration is

Proceduredec ::= 
     Answerspec  PROCEDURE  Procedureheading ;  Statement 
     Answerspec  RECURSIVE  Procedureheading ;  Statement

The second of the above alternatives is the form of a declaration used for recursive procedures (see Section 3.5). The statement following the procedure heading is the procedure body, which contains an answer statement (see Section 7.4) unless the answer specification is void (see Section 8.1), and is treated as a block whether or not it includes any local declarations (see Section 8.4).

8.1. Answer Specification

The value of a typed procedure is given by an answer statement (see Section 7.4) in its body; and its numeric type is specified at the front of the procedure declaration. An untyped procedure has no answer statement, possesses no value, and has no answer specification in front of the word PROCEDURE.

Answerspec ::=