Chapter 8. Procedures

Table of Contents
Answer Specification
Procedure Heading
Parameter Specification
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 ). The statement following the procedure heading is the procedure body, which contains an answer statement (see ) unless the answer specification is void (see ), and is treated as a block whether or not it includes any local declarations (see ).

Answer Specification

The value of a typed procedure is given by an answer statement (see ) 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 ::= 
    Numbertype
        Void