4.7 Constants

A constant is a symbolic name for an MFL value. Constants are defined using const statement:

 
[qualifier] const name expr

where name is an identifier, and expr is any valid MFL expression evaluating immediately to a constant literal or numeric value. Optional qualifier defines the scope of visibility for that constant (see section Scope of Visibility): either public or static.

After defining, any appearance of name in the program text is replaced by its value. For example:

 
const x 10/5
const text "X is "

defines the numeric constant ‘x’ with the value ‘5’, and the literal constant ‘text’ with the value ‘X is ’.

Constants can also be used in literals. To expand a constant within a literal string, prepend a percent sign to its name, e.g.:

 
echo "New %text %x" ⇒ "New X is 2"

This way of expanding constants creates an ambiguity if there happen to be a variable of the same name as the constant. See variable–constant clashes, for more information of this case and ways to handle it.