Eloquence Language Manual
Programs developed for business applications such as company payroll or inventory control can easily contain hundreds of statements. A large program becomes easier to develop, to debug, and to document if it is divided into several program segments, each of which performs a single task. The term program segment may refer to either a main program or a subprogram.
A subprogram is a group of one or more statements that performs a certain task under the control of the calling program segment. The machine runs each main program and each subprogram independently of each other. The program segment which is currently being executed is called the current environment.
A subprogram enables you to repeat an operation many times, substituting different values each time the subprogram is called. Subprograms can be called at almost any point in a program and are convenient and easy to use. In addition to giving greater structure and independence to your programming, subprograms may conserve memory through the use of local variables and dynamic memory allocation.
There are two types of subprograms--multiple-line function subprograms and subroutine subprograms. The multiple-line function subprogram is designed to return a value to the calling program, and is used like a built-in function such as SGN or CHR$. It is defined using the DEF FN statement. A subroutine subprogram is designed to perform a specific task. It is defined using the SUB statement. Subprograms are separate program segments located after the main program in memory.
The statements described in this chapter are:
Subprograms are recorded into disk files, with their accompanying main programs, by using the STORE or SAVE statements described in page 195 . The LOAD SUB statement is available to bring one or more STOREd subprograms back into memory. See page 195 for details.