5.5.1. ASM Function Definition

[Tip]Description

In terms of structured programming languages, an ASM function definition is an associative array (dictionary, map, etc.), which stores data values at locations (slots) defined by its index elements. However, a main difference is that these arrays are very dynamic in the sense that they may store an arbitrarily large number of elements, and the size of the array can be increased at any time during execution in order to store a new element at a specific location (index).

[Important]Syntax
AsmFunctionDefAST ::= OptAnnotationsAST asmfunction TypeNameAST / ArityAST InitialValuesOptAST  

ArityAST ::= DecimalIntegerLiteral

An ASM function is identified by its name and its arity, which is the number of dimensions of the corresponding associative array. In addition, we may optionally provided initial definitions of some slots storing some values at certain locations (initial value). Unused locations of arrays are implicitly storing the undef value.

An ASM function have to be declared at the global scope (that is, at machine scope, outside any rules) prior to its first use.

[Note]Semantics

Mathematically, an ASM function is a partial mapping from its index domain (called location or slot) to its value domain.

While ASM variables have a local scope in the sense that a variable becomes non-accessible as soon as the execution leaves the rule (or the block) of its scope, ASM functionshave a global visibility, thus they are accessible from anywhere during the entire run of an ASM machine. However, the location-value assignments are not persistent, i.e. these are not preserved between different runs of ASM machines (as it is the case in case of model elements in the VPM model space).

Since ASM functions defined in other machines can also be invoked, the interpreter provides lazy initialization for all ASM functions: these are initialized on-demand, i.e. just before their first use.

Defined In:  GTASM Machine

See Also:  ASM function location, update rule