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

substr.f to provide a copy of an embedded character string from a specified position within a<br />

source text string.<br />

Defining a function as "left-handed" indicates that it receives a value, rather than computing one.<br />

<strong>SIMSCRIPT</strong> <strong>II.5</strong> also allows the function substr.f to be used in a left-handed manner. The statement:<br />

let substr.f(STRING,1,3) = "ABC"<br />

replaces the first three character positions in the text variable STRING. The substr.f function<br />

appears to receive, rather than return, a value.<br />

Any function can be defined to be used in both a right- and a left-handed manner. To compute a<br />

value, the right-handed version of the function is called. When a reference is made in a left-handed<br />

manner, that is, to store a value, the left-handed version is called.<br />

No new concepts or statements are involved in the definition of right-handed functions, for all the<br />

functions dealt with thus far have been right-handed. All of the by-now-familiar declarative forms:<br />

function name given argument<br />

function name (argument list)<br />

indicate that the statements that follow, up to the statement end, define a computational process,<br />

hence, a right-handed function. In programs that use both right-and left-handed functions, the word<br />

right may be put before function, but this is optional.<br />

A left-handed function is headed by one of the forms of the routine statement shown above, preceded<br />

by the word left, as in:<br />

and<br />

left function ACCESS given I and J<br />

left function ALLOCATE<br />

In addition to the usual mechanism for transmitting input argument values to a function when it is<br />

called, a left-handed function must have a way of receiving a right-hand-side value. A special statement<br />

of the form:<br />

enter with variable<br />

must be the first executable statement in every left-handed function. It specifies that the value<br />

"computed on the right" and thus transmitted to the left-handed function is to be stored in the named<br />

variable, which can be local or global, unsubscripted, subscripted, or an attribute, for use within the<br />

function. From there on, a left-handed function functions exactly like any other function. It can<br />

store the value, perform computations with it, execute input-output statements, etc. Program 6-3<br />

illustrates the definition and use of right- and left-handed functions.<br />

280

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

Saved successfully!

Ooh no, something went wrong!