18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>SIMSCRIPT</strong> <strong>II.5</strong> <strong>Programming</strong> <strong>Language</strong><br />

As seen in this example, a subprogram variable can be used instead of an actual routine name in<br />

a call statement. When a subprogram variable appears in a call statement, the effect is the<br />

same as a direct call on the routine named in the assignment to the subprogram variable. This<br />

provides a powerful mechanism for directing the selection of routines to be called during program<br />

execution.<br />

Subprogram variables can be global or local, saved or recursive, and subscripted or unsubscripted.<br />

They are initialized to zero in the normal way, and should not be used in a call until a<br />

value has been assigned. Obviously, the numbers of arguments passed through a subprogram<br />

variable cannot be checked against any one routine definition in the preamble. Execution time<br />

checking, however, may still be carried out.<br />

While subprogram arrays can be defined and values assigned to the subscripted elements, subscripted<br />

elements cannot be used directly to reference a routine. This is because of the ambiguity<br />

in the notation used for both subscripts and routine arguments. Any parenthesized variables or<br />

expressions following the subprogram variable are interpreted as given arguments to the routine<br />

being referenced.<br />

Subprogram variables can also be used to call functions. The mode of the subprogram variable<br />

must be declared in a statement of the form:<br />

define variable list as a mode subprogram variable<br />

All functions called indirectly through this variable must be of the declared mode. If no mode is<br />

declared, the current background mode is assumed.<br />

An indirect function call must be indicated by putting a dollar sign ($) before the subprogram variable<br />

name. This is required to distinguish between assignment of values between subprogram<br />

variables and actual function references. If FVAR1 and FVAR2 are declared as subprogram variables,<br />

the statement:<br />

let FVAR2 = FVAR1<br />

assigns to FVAR2 a copy of the value in FVAR1, while:<br />

let VAR = $FVAR1<br />

assigns to VAR a value computed by the function referenced by FVAR1.<br />

Program 2-6 illustrates several of the permissible usages of variables defined as subprogram. The<br />

first example shows a number of routine name literals passed as arguments to a subprogram, which<br />

in turn calls the selected routine indirectly. The second example is similar, but illustrates the use of<br />

a subprogram variable array, comparison operations, and the function notation used with<br />

subprogram variables.<br />

96

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

Saved successfully!

Ooh no, something went wrong!