Literal Expressions

Num Literals

Nonnegative real numbers can be written in the decimal system: as integers, with a decimal point, or in exponential notation.

ProgramTypeValueError
123Num123
1.23Num1.23
01.23Num1.23
.23Num0.23
1.Num1
1.23e2Num123
123E2Num12300
123E+2Num12300
1e-1Num0.1
.1e0Num0.1
0010e-2Num0.1
0e+5Num0

There are no literals for negative, infinity, or NaN values. But they can be created using the builtin -, inf, and nan funcers. For details, see Math Funcers.

ProgramTypeValueError
-1Num-1
-0010e-2Num-0.1
-0Num-0
infNuminf
-infNum-inf
nanNumnan

Str Literals

Strings are sequences of bytes. String literals are delimited by double quotes. Characters inside generally represent the byte sequence that is their UTF-8 encoding. For example:

  • a represents the byte sequence 61 (hexadecimal notation; UTF-8 encoding of Latin Small Letter A)
  • ~ represents the byte sequence 7E (UTF-8 encoding of Tilde)
  • abc represents the byte sequence 61 62 63
  • 日本語 represents the byte sequence E6 97 A5 E6 9C AC E8 AA 9E

There are, however, the following exceptions:

  • \a represents the byte sequence 07 (UTF-8 encoding of Bell character)
  • \b represents the byte sequence 08 (UTF-8 encoding of Backspace)
  • \f represents the byte sequence 0C (UTF-8 encoding of Form feed)
  • \n represents the byte sequence 0A (UTF-8 encoding of Line feed)
  • \r represents the byte sequence 0D (UTF-8 encoding of Carriage return)
  • \t represents the byte sequence 09 (UTF-8 encoding of Horizontal tab)
  • \v represents the byte sequence 09 (UTF-8 encoding of Vertical tab)
  • \\ represents the byte sequence 5C (UTF-8 encoding of Backslash)
  • \" represents the byte sequence 22 (UTF-8 encoding of Quotation mark)
  • \ followed by three octal digits in the range from 000 to 3ff (inclusive) represents the corresponding byte
  • \x followed by two hexadecimal digits represents the corresponding byte
  • \u followed by four hexadecimal digits represents the UTF-8 encoding of the corresponding code point, if defined
  • \U followed by eight hexadecimal digits represents the UTF-8 encoding of the corresponding code point, if defined
  • {{ represents the byte sequence 7B (UTF-8 encoding of Left curly bracket)
  • }} represents the byte sequence 7D (UTF-8 encoding of Right curly bracket)
  • {, followed by a Bach expression, followed by }, represents the UTF-8 encoding of what the expression evaluates to
  • Other uses of \, ", {, or } inside the delimiting quotes are invalid, as is the line feed character
ProgramTypeValueError
"a"Str"a"
"\a"Str"\a"
"\"\\a\""Str"\"\\a\""
"\141"Str"a"
"\x61"Str"a"
"\u65e5\u672c\u8a9e"Str"日本語"
"\U000065e5\U0000672c\U00008a9e"Str"日本語"
"{{}}"Str"{{}}"
"1 + 1 = {1 +1}"Str"1 + 1 = 2"
"{ {a: 1 +1} }"Str"{{a: 2}}"

Arr Literals

Array literals are delimited by square brackets. Inside, a comma-separated sequence of Bach expressions represents the elements. An expression representing an array can be appended as a suffix using a semicolon.

ProgramTypeValueError
[]Arr<>[]
[1]Arr<Num>[1]
[1, 2, 3]Arr<Num, Num, Num>[1, 2, 3]
[1, "a"]Arr<Num, Str>[1, "a"]
[[1, 2], ["a", "b"]]Arr<Arr<Num, Num>, Arr<Str, Str>>[[1, 2], ["a", "b"]]
[1 +1]Arr<Num>[2]
[1;[]]Arr<Num>[1]
[1, 2;[3, 4]]Arr<Num, Num, Num, Num>[1, 2, 3, 4]
[3, 4] =rest [1, 2;rest]Arr<Num, Num, Num, Num>[1, 2, 3, 4]
[1, 2;[1, 2] each(+2)]Arr<Num, Num, Num...>[1, 2, 3, 4]

Obj Literals

Obj literals are delimited by curly braces. Inside, each elements consists of a key, followed by a colon, followed by a value. Elements are separated by commas. The order of elements does not matter. Keys are always strings, but they can be written as identifiers or number literals; they are converted to strings automatically.

ProgramTypeValueError
{}Obj<Void>{}
{"a": 1}Obj<a: Num, Void>{a: 1}
{a: 1}Obj<a: Num, Void>{a: 1}
{1: "a"}Obj<1: Str, Void>{1: "a"}
{"1": "a"}Obj<1: Str, Void>{1: "a"}
{a: 1, b: "c"}Obj<a: Num, b: Str, Void>{a: 1, b: "c"}
{b: 1 +1}Obj<b: Num, Void>{b: 2}