31.12.2013 Views

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

TOPS-20 PASCAL Language Manual - Bitsavers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PROCEDURES AND FUNCTIONS<br />

6.3.1.3 Formal Procedure and Function Parameters - <strong>PASCAL</strong> allows<br />

procedures and functions to be passed as parameters to other<br />

procedures or functions. To do this, a full procedure or function<br />

heading is given as one parameter of the procedure being declared.<br />

For example, the following procedure declaration specifies one value<br />

parameter and one function parameter:<br />

F' f~ 0 C E D U I:~ E ACT U A L.<br />

(V A l..! J NT E G E r~ ,<br />

FUNCTION FORMAL.<br />

(Fl:INTEGER):INTEGER);<br />

VAL. := FORMAL (VAL + 1),<br />

The formal function parameter takes one value integer parameter, and<br />

returns an integer value. When procedure ACTUAL is called, you need<br />

to supply it with two parameters: an integer value; and, the name of<br />

a function which takes one integer argument and returns an integer<br />

value. Note that ONLY the function name is passed to the procedure;<br />

do NOT supply the function's parameters in the procedure call. They<br />

are supplied when the procedure calls the function.<br />

The parameter list of the formal procedure or function may consist of<br />

anything that can be defined in a normal procedure or function<br />

declaration, including value parameters, VAR parameters, conformant<br />

arrays, and even other procedures and functions. These procedures and<br />

functions obey the same rules as the formal procedure or function of<br />

which they are a parameter.<br />

The following is an example of a procedure heading with formal<br />

procedures nest~d to two levels:<br />

PROCEDURE OUTER(PROCEDURE FORMAL1(FUNCTION FORMAL2:REAL, B:REAL»,<br />

Procedure OUTER has one parameter, a procedure. This procedure has<br />

two parameters, a real-typed function (with no parameter.s) and a real<br />

value parameter.<br />

When a subprogram is called with a procedure or function parameter,<br />

the parameter lists of the formal and actual parameters must be<br />

congruous. This means that the parameter lists must have the same<br />

number of parameters; and each corresponding parameter must be of the<br />

same kind (value, VAR, etc.) and of the same type. In the following<br />

example, procedure YOU BET could be passed as a parameter to procedure<br />

OUTER above, because Y5U BET and FORMALl have congruous parameter<br />

lists.<br />

PROCEDURE YOU_BET(FUNCTION YOU:<br />

REAL, BET: REAL),<br />

In the following example, procedures PRINTHEX and PRINTOCTAL have<br />

congruous parameter lists. Procedure PRINTBINARY's parameter list is<br />

not congruous to either of the others because both of its parameters<br />

are value parameters.<br />

PROCEDURE PRINTHEX (VAL: INTEGER, VAR SIZE: INTEGER),<br />

PROCEDURE PRINTOCTAL. (I: INTEGER, VAR F: INTEGER),<br />

PROCEDURE PRINTBINARY (NUM:<br />

INTEGER, WIDTH: INTEGER),<br />

f)-24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!