Literals

Literal Expressions, or simply Literals, are constant values expressed directly in code by providing a concrete, hardcoded number or string value.

Integer Literals

The default type of an Integer Literal is determined by the first type from the following list that can hold the number: Int32, UInt32, Int64, UInt64 and BigInteger (the latter currently limited to the .NET platform).

Integer Literals are supported as decimal (default) or as hexadecimal and binary (with $ and % prefixes, respectively). Spaces are allowed within the number to logically group digits, commonly in blocks of 3 for decimal, 4 for hexadecimal and 8 for binary.

var MyInteger := 153; // Decimal (Base 10) integer literal
var MyHexInteger := $100; // Hexadecimal (Base 16) integer literal with a value 256
var MyBinaryInteger := %101; // Binary (Base 2) integer literal with a value of 5
var MyBigInteger := 698574357436578436543275894375984326598342759435634977653476574392865784356;
var MySpacedInteger := 500 000;
var MySpacedHexInteger := $c000 0000;

Floating Point Literals

Floating Point Literals can be defined by including a decimal point in the literal, or by using exponential notation with the letter E (upper or lower case). Note that floating point literals only accept decimal numbers, not hexadecimal or binary.

var MyFloat := 153.0;
var MySecondInteger := 123E3; // 123000.0

String and Character Literals

String Literals start with a single quote (') or double quote (") and end with the same type of quote that started it. Within the string, occurrences of the quote character can be escaped by duplicating it.

Literals enclosed with single quotes (') and consisting only of a single character are considered to be Character Literals by default, but the compiler will smartly 'upgrade' them to string literals, if it detects that a string is expected in the current context. Literals enclosed with double quotes (") will always be strings.

Literals enclosed with a double quote (") may contains line breaks, in order to to define multi-line strings.

Character Literals can also be expressed as Character Code Literals – which are made up by a hash symbol (#) followed by a 16-bit value indicating the characters' unicode, without quotation marks. A hexadecimal code can be used if prefixed with $.

var linefeed = #10;
var carriageReturn = #$0d;

String literals can be concatenated with +, or linked/interspersed by Character Code Literals without the need for an explicit +.

var MyString := 'Hey there!';
var MyString2 := "Don't Stop Believing" // The apostrophe is fine because the string is surrounded by double quotes
var MyString3 := 'Don''t Stop Believing' // The apostrophe escaped
var MyString3 := 'Don'#0039't Stop Believing' // The apostrophe as character code literals
var MySingleChar := 'x'; // A Char, because length is 1
var MySingleCharString: String := 'x'; // Treated as string based on context

Interpolated Strings

String Literals can be interpolated with values at runtime, if they are prefixed by a dollar ($) character. Inside an interpolated string literal, any range of code surrounded by curly braces ({...}) will be interpreted as a code expression, which will be compiled, evaluated at runtime and inserted in the string at this position.

var TimeString := $'It is {DateTime.UtcNow} o'' clock!';

To use a literal curly brace inside an interpolated string, the brace can be duplicated from escape interpolating:

var lValue := 5;

var MyString := $'The {{curly} gets replaced by a {lValue}'; // "The {curly} gets replaced by 5"

For obvious reasons interpolated string literals cannot be used for Constants (and are not technically literals).

Boolean Literals

The true and false keywords can be used to express Boolean literal values.

var oxygeneRocks = true;
var oxygeneIsCaseSensitive = false;

Nil Pointer Literals

The nil keyword can be used to express a nil pointer, reference type or a nullable type without value.

var b := nullable Boolean := nil;