Constants

Section - TM Language Reference

Constants can be expressed as literals in a statement eg:

<targetelement> := 'A string constant';

SML does not support figurative (symbolic) constants except as described below.

Figurative Constants

The only figurative constants in SML are TRUE and FALSE.  A local or global variable can be used within a Transform to give a name to an unchanging value if required, but note that it is not truly a constant.

For example, instead of repeatedly using the literal value 3.141… in multiple statements in a Transform, you could define a variable and use that variable instead:

ConstPI := 3.141592654;

You should not rely on ConstPI being initialised outside of the Transform where it is used.

You can initialise variables and create constants in GLOBAL and LOCAL blocks, eg:

global

    myconst : string == 'hello';

    myvar   : string := 'my non const';

    myuninit : string;

end_global;

myconst is then constant because of == and cannot be modified (myconst := 'a'; in a transform would yield a compile time error).
myvar is initialised to 'my non const', but can be subsequently assigned.
myuninit is an ordinary non initialised global var.

The same can occur for LOCAL ... END_LOCAL vars.