Literals

M has both string and numeric literals.

String Literals

A string literal (strlit) is enclosed in quotation marks (" ") and can contain a sequence of ASCII and Unicode characters. While the standard indicates the characters must be graphic, GT.M accepts non-graphic characters and, at compile-time, gives a warning. Using $CHAR() and concatenate to represent non-graphic characters in strings not only avoids the warning but is less error prone and makes for easier understanding. M attempts to use character text that appears outside of quotation mark delimiters according to context, which generally means as a local variable name.

To include a quotation mark (") within a strlit, use a set of two quotation marks ("" "").

Example:

GTM>write """"
"
GTM>

The WRITE displays a single quotation mark because the first quotation mark delimits the beginning of the string literal, the next two quotation marks denote a single quote within the string, and the last quotation mark delimits the end of the string literal.

Use the $CHAR function and the concatenation operator to include control characters within a string.

Example:

GTM>WRITE "A"_$CHAR(9)_"B"
A B
GTM>

The WRITE displays an "A," followed by a tab (<HT>), followed by a "B" using $CHAR(), to introduce the non-graphic character.

Numeric Literals

In M, numeric literals (numlit) are entered without surrounding delimiters.

Example:

GTM>WRITE 1
1
GTM> WRITE 1.1
1.1

These display numeric literals that are integer and decimal.

M also accepts numeric literals in the form of a mantissa and an exponent, separated by a delimiter of "E" in uppercase. The mantissa may be an integer or a decimal fraction. The integer exponent may have an optional leading minus sign (-).

Example:

GTM>WRITE 8E6
8000000
GTM> WRITE 8E-6
.000008
GTM>
[Caution] Caution

The exponential numeric form may lead to ambiguities in the meaning of subscripts. Because numeric subscripts collate ahead of string subscripts, the string subscript "01E5" is not the same as the numeric subscript 01E5.

GT.M handles numeric strings which are not canonical within the implementation as strings unless the application specifically requests they be treated as numbers. Any use in a context defined as numeric elicits numeric treatment; this includes operands of numeric operators, numeric literals, and some intrinsic function arguments. When the code creates a large number out of range , GT.M gives a NUMOFLOW error. When the code creates a small fractional number out of range GT.M treats it as zero (0). The GT.M number range is (to the limit of accuracy) 1E-43 to 1E47. When the application creates an in-range number that exceeds the GT.M numeric accuracy of 18 significant digits, GT.M silently retains the most significant digits. With standard collation, GT.M collates canonic numeric strings used as subscripts numerically, while it collates non-canonic numbers as strings.