Literals

EGL supports the following kinds of literals: character, numeric, and list.

Character literals

At this writing, all character literals are of type string or string(n), as in the following examples:
  • myString string = "EGL is said to be \"elegant\" because it is.";

    As shown, you can use an escape character to include double quotes in the string.

  • myString string(3) = "EGL";

Numeric literals

Numeric variables consist of digits and can include a decimal point, a plus or minus sign, and the letter "E" or "e" for scientific notation.

Unless you specify otherwise, the following rules apply:
  • A literal with a decimal point and without scientific notation is of type decimal.
  • A literal with scientific notation is of type float. Here is an example:
    myFloat FLOAT = 2.539e7;
  • A literal without a decimal point is of type int.

You can specify the type of a numeric literal by adding a character, as shown next.

Table 1. Numeric literals
Literal type Character to append Example
smallint i
mySmallInt smallInt = 123i;
bigint I
myBigInt bigInt = 123I;
smallfloat f
mySmallFloat smallFloat = 12.34f;
float F
myFloat float = 12.34F;

List literals

A list literal consists of a pair of brackets that contains a comma-separated list of literals (including other list literals) or expressions (including lists). Each list literal has a type, and can be used anywhere an array of the given type is allowed, for instance, as an initializer for an list. The next table gives examples.

Table 2. List literals
Array literal Type
[ 1i, 2i, 3i ] smallInt[]
[ "hi", "Mom" ] string[]
[ new myRecord, new myRecord ] myRecord[]
[ (myPay < 0), (myPay > 0) ] boolean[]
[ [ 1, 2 ], [ 3, 4 ] ] int[][]
[ 3, "cow", [ 4.5, 6.7 ] ] any[]

If the types of the elements in the list literal differ, the element type is ANY. The elements in the array do not need to be assignment compatible with one another.