Literals

Summary:
  • A literal is a constant value.
  • The Curl® language supports numeric, Boolean, character, string, and quantity literals, as well as the null literal.
A literal is an expression that evaluates to a constant value. For example, a number such as 7 is a literal and a character such as 'a' is a literal. The Curl language supports the following types of literals:

Numeric Literals

Summary:
  • A number is a numeric literal.
  • The Curl language supports integer, floating-point literals and Decimal literals.
A number is a numeric literal. For example, 7 and 3.25 are numeric literals. In particular, there are three types of numeric literal:

Integer Literals

Summary:
  • An integer literal is a whole number with no portion to the right of a decimal point.
  • Decimal (or base 10) is the default number system for integer literals.
    Use the 0b or 0B prefix for binary (base 2) numbers.
    Use the 0o or 0O prefix for octal (base 8) numbers.
    Use the 0x or 0X prefix for hexadecimal (base 16) numbers.
    Use the u suffix for unsigned numbers.
An integer literal is a whole number with no portion to the right of a decimal point. That is, an integer literal is a constant integer value. Integer literals have the following form:
[-]whole-number[u]
where the optional minus sign indicates a negative number and the optional u suffix indicates that an unsigned value should be produced. If both - and u are specified, then the value will first be parsed as a negative number and then coerced to an unsigned integer with the same underlying bit pattern.
The following numbers are valid integer literals:
Note: The Curl language allows leading zeros in integer literals.
Decimal (or base 10) is the default number system for integer literal; however, by prefixing an integer literal with a special code, you can specify integer literals in other number systems. Note that when specifying numbers in a non-decimal base the value will be interpreted as a raw bit value, so that numbers in the range above max-int up to max-uint will be interpreted as a negative number rather than producing a int64 or uint value. For instance 0xFFFFFFFF is equivalent to -1 not 4294967295. The following table describes the number system prefixes:
Number SystemPrefixExample
Binary (base 2)0b or 0B0b00100010
Octal (base 8)0o or 0O0o42
Hexadecimal (base 16)0x or 0X0x2A
See Primitive Types: Integers for information about the integer data types in the Curl language.

Floating-point Literals

Summary:
  • A floating-point literal is a number with a portion to the right of a decimal point.
  • A floating-point literal can be in scientific notation.
A floating-point literal is a constant floating-point value. There are two forms of floating-point literals:
Numbers with a portion to the right of a decimal point have the following form:
[-][whole-number].decimal-part
where the optional minus sign indicates a negative number. The following are valid floating-point literals:
Numbers in scientific notation have the following form:
[-][whole-number][.decimal-part]e[-]exponent
where the optional minus signs indicate negative numbers. The whole-number and decimal-part are optional, although you must specify at least one of them. The following are valid floating-point literals (and equal in value to the literals in the example above):
Note: All floating-point literals are treated as double values. For example, 3e4, which is 30000, is treated as a double and not as an int.
An f suffix on the number makes a float literal, rather than a double literal. Float literals are an advanced feature, useful when assigning constants to float variables or performing arithmetic where promotion to double is not desired. For example:
See Primitive Types: Floating-point Numbers for more information about the floating-point data types in the Curl language.

Decimal Literals

Summary:
  • A Decimal literal represents a constant of type Decimal.
  • Use the i suffix for Decimal literal.
  • A Decimal literal can be in scientific notation.
A Decimal literal is a constant Decimal value. An i suffix on the number makes a Decimal literal. Decimal literals are an advanced feature, useful when assigning constants to Decimal variables. There are three forms of Decimal literals:
Numbers with a portion to the right of a decimal point have the following form:
[-][whole-number].decimal-part
where the optional minus sign indicates a negative number. The following are valid Decimal literals:
Numbers in scientific notation have the following form:
[-][whole-number][.decimal-part]e[-]exponent
where the optional minus signs indicate negative numbers. The whole-number and decimal-part are optional, although you must specify at least one of them. The following are valid Decimal literals (and equal in value to the literals in the example above):
Note: All Decimal literals are treated as Decimal values. For example, 3e4i, which is 30000, is treated as a Decimal and not as an int.

Boolean Literals

Summary:
  • A Boolean literal is a Boolean value.
  • It can have one of two values: true or false.
Boolean values are language primitives and are represented by the data type bool. Boolean literals can have one of the following two values:
See Primitive Types: Boolean Values for more information about the Boolean data type in the Curl language.

Character Literals

Summary:
  • A character literal is a single character.
  • It can be a single character enclosed in single quotes.
  • It can be an escape sequence in single quotes.
  • In operations, character literals are converted to their equivalent numeric value.
A character literal is a single character. It can have either of the following forms:
An escape sequence specifies a character that does not appear on the keyboard or a character that might otherwise cause the runtime to misinterpret the character literal. Characters that do not appear on the keyboard include newline, carriage return, and tab characters. Characters that you must escape to avoid misinterpretation include single quotes and backslashes. An escape sequence begins with the escape character (\). The following table describes the escape sequences for character literals:
Escape SequenceDescription
\uXXXXSpecial character, where XXXX is the Unicode hexadecimal value of the character. Values greater than 0xFFFF cannot be represented using this sequence.
\UXXXXXXXXSpecial character, where XXXXXXXX is the Unicode hexadecimal value of the character
\nNewline character
\rCarriage return character
\tTab character
\'Single quote character
\"Double quote character
\\Backslash (escape) character
\{Left curly brace
\}Right curly brace
\|Vertical bar
\ Non-breaking space
\=Equal sign
\[Left square bracket
\]Right square bracket
\(Left parenthesis
\)Right parenthesis
The last four characters do not have to be escaped, but doing so may help prevent confusion on behalf of editors that match brackets and parentheses.
The Curl language allows you to use character literals in operations. When performing an operation on a character literal, the Unicode value of the character is used. The character literal is converted to a numeric literal and the operation is performed. For example:

Example: Character Literals in Operations
{VBox
    || Add the character literal 'c' and the integer 3...
    || Note that the Unicode value of 'c' is 99.
    {text 'c' + 3 is ... {value 'c' + 3}},

    || Subtract 3 from the character literal 'd'...
    || Note that the Unicode value of 'd' is 100.
    {text 'd' - 3 is ... {value 'd' - 3}},

    || Subtract the character literal 'a' from the
    || character literal 'd'.  Note that the Unicode
    || values for 'a' is 97.
    {text 'd' - 'a' is ... {value 'd' - 'a'}},

    || Subtract the character literal 'd' from the
    || character literal 'd'.
    {text 'a' - 'd' is ... {value 'a' - 'd'}},

    || Is 'c' + 3 equal to the character literal 'f'...
    || Note that the Unicode values for 'f' is 102.
    {text 'c' + 3 == 'f' is ... {value 'c' + 3 == 'f'}}
}
Note: In the example above, the operator expressions, such as 'c' + 3, are enclosed within value expressions. Within a text format, you must use the value expression to treat the enclosed code as an expression instead of text.
See Primitive Types: Characters for information about the character data type in the Curl language.

String Literals

Summary:
  • A string literal is a sequence of zero or more characters.
  • Enclose a string literal in double quotes (").
A string literal is a fixed String of text. String literals consist of zero or more characters and are enclosed in double quotes ("). A string literal with zero characters between the double quotes ("") is the empty string.
Within a string literal, you can include escape sequences for characters that do not appear on the keyboard or for characters that might otherwise cause the runtime to misinterpret the string literal. In particular, you must be sure to escape double quotes and reserved characters in string literals. String literals may use any of the same escape sequences as character literals, as shown in the table above.
If a string literal contains many escape sequences, you should consider using a verbatim string instead. See Verbatim Strings for more information on this topic.
To concatenate strings, the Curl language provides the string concatenation operator (&). See the Operators chapter for more information about the string concatenation operator.

Example: String Literals
{VBox
    || A string literal with some text that includes spaces...
    "string literal text",

    || The empty string...
    "",

    || A string literal consisting of one double quote...
    "\"",

    || A string literal spanning multiple lines...
    "This is a
    multiple line
    string",

    || A string literal spanning multiple lines with
    || extra whitespace...
    "This is a
    multiple line

    string with extra         whitespace",

    || Using the string concatenation operator...
    "\"" & "string literal text" & "\""
}
When representing string literals internally, the runtime stores each character of the string literal. If there are a number of spaces between two words, it stores each individual space character, thus preserving whitespace in string literals. Whitespace is collapsed when content is displayed. This means that, even though the internal representation of a string literal preserves whitespace, the printed representation of the string literal does not preserve whitespace.
Note: When the Output Log displays a string, it does not collapse whitespace.
See Strings for information about string class types.

Quantity Literals

Summary:
  • A quantity literal consists of a numeric literal followed by a unit of measure.
A quantity literal consists of a numeric literal followed by a unit of measure, with no space in between. For example:
When performing operations on quantity literals, the runtime understands the unit of measure. For example, it allows you to add 5cm (5 centimeters) to 5m (5 meters) and returns the correct result (5.05m). See Quantities and Units for a complete description of quantities and the supported units of measure and Primitive Types: Quantities for information about the quantity data types in the Curl language.
Note: As with floating-point literals, quantity literals are typically represented as double values, and arithmetic on them takes place as double-precision floating-point. In the unusual cases where a quantity with a float representation is desired, the f suffix can be used, just as for float literals. To separate the f suffix from the unit of measure, the unit of measure must be contained within parentheses. For example:

The null Literal

Summary:
The value null is a literal.
The null value is a special constant used as a placeholder when variables of extended "maybe-null" class types and procedure types do not refer to an object.
See The null Value for information on how null is used in the Curl language.