2018-01-04 00:15:04 +00:00
|
|
|
|
# Literals and initializers
|
2018-02-27 12:26:56 +00:00
|
|
|
|
|
|
|
|
|
## Numeric literals
|
|
|
|
|
|
|
|
|
|
Decimal: `1`, `10`
|
|
|
|
|
|
|
|
|
|
Binary: `%0101`, `0b101001`
|
|
|
|
|
|
2018-03-03 00:21:57 +00:00
|
|
|
|
Quaternary: `0q2131`
|
|
|
|
|
|
|
|
|
|
Octal: `0o172`
|
|
|
|
|
|
2018-02-27 12:26:56 +00:00
|
|
|
|
Hexadecimal: `$D323`, `0x2a2`
|
|
|
|
|
|
|
|
|
|
## String literals
|
|
|
|
|
|
|
|
|
|
String literals are surrounded with double quotes and followed by the name of the encoding:
|
|
|
|
|
|
|
|
|
|
"this is a string" ascii
|
|
|
|
|
|
|
|
|
|
Characters between the quotes are interpreted literally,
|
|
|
|
|
there are no ways to escape special characters or quotes.
|
|
|
|
|
|
2018-04-02 17:47:11 +00:00
|
|
|
|
In some encodings, multiple characters are mapped to the same byte value,
|
|
|
|
|
for compatibility with multiple variants.
|
|
|
|
|
|
2018-02-27 12:26:56 +00:00
|
|
|
|
Currently available encodings:
|
|
|
|
|
|
|
|
|
|
* `ascii` – standard ASCII
|
|
|
|
|
|
|
|
|
|
* `pet` or `petscii` – PETSCII (ASCII-like character set used by Commodore machines)
|
|
|
|
|
|
|
|
|
|
* `scr` – Commodore screencodes
|
|
|
|
|
|
2018-04-02 17:47:11 +00:00
|
|
|
|
* `apple2` – Apple II charset ($A0–$FE)
|
|
|
|
|
|
|
|
|
|
* `bbc` – BBC Micro and ZX Spectrum character set
|
|
|
|
|
|
2018-04-02 19:06:18 +00:00
|
|
|
|
* `jis` or `jisx` – JIS X 0201
|
2018-04-02 17:47:11 +00:00
|
|
|
|
|
|
|
|
|
* `iso_de`, `iso_no`, `iso_se`, `iso_yu` – various variants of ISO/IEC-646
|
|
|
|
|
|
|
|
|
|
* `iso_dk`, `iso_fi` – aliases for `iso_no` and `iso_se` respectively
|
|
|
|
|
|
2018-02-27 12:26:56 +00:00
|
|
|
|
When programming for Commodore,
|
|
|
|
|
use `pet` for strings you're printing using standard I/O routines
|
|
|
|
|
and `scr` for strings you're copying to screen memory directly.
|
|
|
|
|
|
2018-04-02 19:06:18 +00:00
|
|
|
|
## Character literals
|
|
|
|
|
|
|
|
|
|
Character literals are surrounded by single quotes and followed by the name of the encoding:
|
|
|
|
|
|
|
|
|
|
'x' ascii
|
|
|
|
|
|
|
|
|
|
From the type system point of view, they are constants of type byte.
|
2018-02-27 12:26:56 +00:00
|
|
|
|
|
|
|
|
|
## Array initialisers
|
|
|
|
|
|
|
|
|
|
An array is initialized with either a string literal,
|
|
|
|
|
or a list of byte literals and strings, surrounded by brackets:
|
|
|
|
|
|
|
|
|
|
array a = [1, 2]
|
|
|
|
|
array b = "----" scr
|
|
|
|
|
array c = ["hello world!" ascii, 13]
|
|
|
|
|
|
|
|
|
|
Trailing commas (`[1, 2,]`) are not allowed.
|