18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Advanced Topics<br />

6.5 Attribute Definitions: Functions<br />

When defined by statements of the form:<br />

the system has an attribute name function<br />

every entity name has an attribute name function<br />

a system attribute or an attribute of a permanent or temporary entity is treated as a function and not<br />

as a variable. Any reference to such a function attribute is in effect a reference to a function routine<br />

with the same name. That is, a subprogram having the same name as the declared attribute must be<br />

included as one of the program routines. The routine must have the same number of arguments as<br />

the declared or implied dimensionality of the attribute, that is, no arguments for an unsubscripted<br />

system attribute, one argument for a temporary or permanent entity, two arguments for a two-dimensional<br />

system attribute, etc.<br />

Function attributes, because they are computational procedures, have no storage space allocated to<br />

them. Declarations of attributes as functions interspersed between other attribute declarations have<br />

no effect, therefore, on storage allocation of attributes to arrays or entity records. To illustrate:<br />

Declaration:<br />

every AUTO has a FUEL FUNCTION, a CONSUMPTION.RATE,<br />

a FUEL.CAPACITY and a DEPARTURE.TIME<br />

Entity structure:<br />

word 1<br />

word 2<br />

word 3<br />

CONSUMPTION.RATE<br />

FUEL.CAPACITY<br />

DEPARTURE.TIME<br />

Assume the function attribute, FUEL, is defined by the following routine:<br />

routine FUEL(AUTO)<br />

return with FUEL.CAPACITY(AUTO) -<br />

(TIME - DEPARTURE.TIME(AUTO)) *<br />

CONSUMPTION.RATE(AUTO)<br />

end<br />

Assuming that the value of the current time is maintained in a global variable, TIME, the amount of<br />

fuel currently remaining in a particular auto is calculated at each apparent attribute reference of the<br />

type:<br />

let AMOUNT = FUEL(AUTO)<br />

As the variable TIME changes, the reported value of FUEL(AUTO) changes.<br />

271

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

Saved successfully!

Ooh no, something went wrong!