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.

Modelling Concepts<br />

Experience has shown that some programmers prefer to write for each JOB, rather than for I<br />

= 1 to N.JOB even if JOB has not been defined as a permanent entity. That is, they prefer not to<br />

make up a local variable name (I in this instance) just to step through a sequence of values from 1<br />

to N (N.JOB in this instance), but would rather use a name that is easy to remember and has some<br />

meaning. To facilitate this, the phrase:<br />

include entity name list<br />

can be appended to a permanent entities statement, as in:<br />

permanent entities include ADULT, COUNTRY and FISH<br />

This phrase defines the listed names as permanent entities, without attributes, but with the associated<br />

global variables entity and N.entity. The above statement defines the global variables<br />

ADULT, N.ADULT, COUNTRY, N.COUNTRY, FISH, and N.FISH and permits such phrases as:<br />

and<br />

for every ADULT<br />

for each COUNTRY<br />

for all FISH<br />

to be used. The following short example illustrates why this might be a useful shorthand.<br />

Program preamble:<br />

permanent entities include ELEMENT<br />

Main program:<br />

read N.ELEMENT<br />

reserve LIST(*) as N.ELEMENT<br />

for each ELEMENT, let LIST(ELEMENT) = 1<br />

It should be clear that such a statement is impossible for temporary entities. Scattered throughout<br />

memory, rather than stored sequentially, temporary entities cannot be indexed by ordinal numbers;<br />

they can only be pointed to by set pointers. To process all the temporary entities of a given class,<br />

the entities must be stored in a set as they are created, and must be processed by a statement that<br />

deals with the set. This statement, which by its nature deals with both permanent and temporary<br />

entities, has two basic forms:<br />

1. for each variable of set<br />

2a. for each variable from arithmetic expression of set<br />

2b. for each variable after arithmetic expression of set<br />

Form 1 selects entities that are members of an indicated set, in order of their ranking, assigning the<br />

entity pointer values to the named variable. If the set is empty, all of the statements controlled by<br />

165

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

Saved successfully!

Ooh no, something went wrong!