Literal constants are the simplest expressions in Freya. They are available only for a small set of predefined data types:
Literal integer constants come in two flavors: decimal and hexadecimal literals. Decimal constants contains decimal digits and may include underscores as thousand separators, in order to enhance readability:
12345 // Ok: a "flat" decimal integer constant. 12_000_000 // Ok: underscores are used as thousand separators. 12_000000 // ERROR: inconsistent use of underscores. 10_0 // ERROR: underscores in a wrong position.
On the other hand, hexadecimal integer constants always starts with a dollar sign and may contain decimal digits or characters from 'A' to 'F'. Character case is not significative:
$C0FEE // Ok: an hexadecimal integer constant. 1234F5 // ERROR: The initial dollar sign is missing.
Real constants can belong either to the System.Double or the System.Single predefined data type. Double precision constants look like these:
1.00 // Ok: it has a decimal point. .103 // Digits are not required before the decimal point. 1E9 // Ok: no decimal point, but an exponent. 1.5E9 // Ok: a decimal point and an exponent.
Of course, integer constants can be reinterpreted as double precision real constants when needed.
Single precision real constants are almost identical to double precision constants, except they end with an 'F' character:
1.00F // Ok! .103F 1E9F 1.5E9F 200F // This is not an integer constant, since it has an "F" sufix!
Integer constants may also be converted into single precision real constants when required.
There are two predefined boolean constants:
true false
String constants in Freya can be enclosed between single or double quotes:
"This is a string" // Ok. 'This is a string' // Ok: same as above.
Single quotes can be freely used inside string constants delimited by double quotes, and viceversa:
"What's up, doc?" // Ok: a single quote inside double quotes. '"Cookies!", he said.' // Ok: double quotes inside single quotes.
If you must use a single quote inside a string constant delimited by singles quotes, you must duplicate the single quote:
'You''ve said: "cookies"'
Non printable characters can be embedded inside string constants using their Unicode numerical values. This string has an embedded "car return/line feed" sequence:
'First line'#13#10'Second line'
In the above example, we have used the decimal representation for the numerical codes. You can also use the hexadecimal representation by using "#U" or "#u" instead of a plain "#":
'First line'#u000D#UA'Second line'
Please note that both the 'U' prefix and any hexadecimal digits, are case insensitive.
The Freya Programming Language
Expressions
Literal arrays
Instantiation
Constructors
Array types