The text read off it
[page 32]
Functions
While the term “function” is often associated with mathematics, the concept has certain general applications that can greatly simplify the writing of programs. Accordingly, the Commercial Translator system has been designed to handle certain kinds of functions as an added convenience to the programmer.
The term function is used in the Commercial Translator to mean a result obtained as a consequence of some procedure. More precisely, it means a result obtained from a procedure specified by a BEGIN SECTION command, and, in particular, it is a result named in the GIVING clause of that command.
For example, in the command BEGIN SECTION USING A, B, C GIVING MINIMUM, the name MINIMUM is a function-name. This name refers to a field in storage which will contain the function after the procedure specified by this command has been carried out. (A hypothetical procedure of this type will be described and explained presently.)
The reader will note that this command also contains a clause beginning with the word USING and that three data-names (A, B, and C) have been specified in that clause. These names represent data which will be used in obtaining the function. The three items of data are called parameters, and the three names are parameter-names. The term “parameter” is limited, in the Commercial Translator system, to data named in the USING clause of the BEGIN SECTION command.
Each of these names—the function-name and the three parameter-names—identifies a field in storage. At object time the three parameter fields will contain data to be used in the procedure, and the rules governing the DO command (which causes the procedure to be executed) provide a means by which the data will be placed automatically in those fields.
To illustrate the use of functions and parameters, a sample procedure will be examined in detail. Suppose that the programmer wishes to determine which of three values is the lowest, so that he can use it elsewhere in the program. Suppose, further, that he wishes to be able to compare values of different kinds and therefore wishes to use a procedure that can be used with data from a variety of sources. For this purpose he has written a procedure called MINIMUM.ROUTINE, which consists of the following procedure statements:
MINIMUM.ROUTINE. BEGIN SECTION USING A, B, C GIVING MINIMUM.
IF A IS LESS THAN B THEN MOVE A TO MINIMUM OTHERWISE
MOVE B TO MINIMUM.
IF C IS LESS THAN MINIMUM THEN MOVE C TO MINIMUM.
END MINIMUM.ROUTINE.
The name MINIMUM.ROUTINE identifies this procedure so that the programmer can refer to it elsewhere in the program. For purposes of illustration, it will be assumed that the programmer has written the following command later in the program:
DO MINIMUM.ROUTINE USING D, E, F GIVING MINIMUM.2.
It is important to see precisely what happens in this case. First of all, when the processor encounters the MINIMUM.ROUTINE section as it is originally written, it will note the three parameter-names (A, B and C) and the function-name (MINIMUM). It will examine the entries written for those names in the data description (which will be discussed in Chapter 4) and will obtain information about the amount of storage space to be reserved for each, together with certain other technical details.
