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 />

arguments are transmitted and received is clear: at entry to the routine, the given value of X is used<br />

to initialize the local argument NUMBER; at return from the subprogram, the named variable, in this<br />

case X, is replaced by the resulting yielded argument, SQRT. Note that the same names may be used<br />

in both the call statement and the routine definition, as in the fourth example above. In the call<br />

statement, the given and yielding arguments refer either to variables local to the routine or to global<br />

variables. In the routine, however, these arguments are always taken as definitions of variables local<br />

to the routine, and thus, within the routine, do not directly reference the variables appearing in<br />

the call statement.<br />

It is important to note that the variables listed as given or yielded arguments in a routine reference<br />

must match exactly, in number and mode, the arguments listed in the formal argument list in the<br />

routine definition. No automatic mode conversions, between integer and real, for example,<br />

may be assumed. Obviously, all references to a subprogram in different places in a program should<br />

include the same numbers of both given and yielding arguments. In order that any incorrect references<br />

may be diagnosed at program compilation, it is possible to define, in the program preamble,<br />

the "correct" numbers of arguments, using a statement of the form:<br />

define name as a routine given i arguments yielding j arguments<br />

More than one routine may be defined in the same statement; a is optional, and the word routines<br />

may be used. The word values is synonymous with arguments, and with and giving with<br />

given. Either or both of the given or yielding phrases may be omitted. If either is omitted the<br />

routine is assumed to have no such arguments. If neither given nor yielding phrases are included,<br />

compilation checks on argument numbers at each routine reference are omitted. Otherwise,<br />

inconsistent argument numbers will result in error messages. Some implementations provide for<br />

additional checks during program execution. Consult the relevant user's guide for options on such<br />

checking.<br />

2.13 Routines Used as Functions<br />

A function is a procedure that yields a single result value when applied to some given value. The<br />

value yielded is termed the result of the function, or the function value. Calculation of the square<br />

root of a given number could be considered to be a function evaluation, and a routine may be written<br />

to provide this service. The call statement, however, is a cumbersome way of referencing routines,<br />

which return only a single result value.<br />

When a function is used in a mathematical expression, it indicates that the value that results from<br />

applying the function to the appropriate given values should be used in evaluating the expression.<br />

In programming, a function notation provides a convenient way to reference a subprogram that returns<br />

only a single result value. A subprogram that is to be referenced as a function is written in<br />

much the same way as subprograms discussed previously, requiring only minor changes in definition.<br />

The function symbol is the name of the function routine. If the routine SQUARE.ROOT were<br />

defined as a function, it could be referenced with a direct use of the name; as follows:<br />

62

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

Saved successfully!

Ooh no, something went wrong!