4. Literals
4.1 Boolean and absence#
true, false, and none. none takes its optional type from context; it is never a universal null.
4.2 Integers#
42 1_000_000 0xff 0o755 0b1010_1100 255u8 -20i32Underscores may separate digits. Based prefixes are lowercase. Context chooses the integer type; absent context the default is i64, except in a variadic C argument position, where it is c.int (§17.2). A suffix names an exact type. An untyped expression computes in the contextual type, 3 -| 7 as u8, and a literal outside that type's range is a compile error wherever it sits in the expression. A negative literal is unary minus applied directly to a positive literal; -9223372036854775808 is accepted as i64 although its positive part alone is out of range, where -(9223372036854775808) is not a negative literal and is refused.
4.3 Floats#
1.0 6.022e23 0.5f32 1_000.25Context chooses the float type; absent context the default is f64, or c.double in a variadic position. Conversion from decimal is correctly rounded. NaN and the infinities are not literals; luce-std's math module names them as constants.
4.4 Characters and text#
'A' # one Unicode scalar: char; adapts to u8 when ASCII
"hello" # UTF-8 text: str, static, NUL-terminated
b"\x89PNG\r\n" # bytes: const u8[] static data; u8[6] where one is expected
r"C:\studio\shots" # raw: no escapes, no interpolation
f"frame {frame}: {status}" # formatted; see §5.5
"""multiline
text"""- A character literal is one Unicode scalar after escapes. In a
u8context an ASCII character literal is that byte, sobyte == '\n'needs no conversion; in an index position it is that integer, sotable['P']indexes. - A string literal is valid UTF-8, stored once in static data, and followed by a NUL byte that is not part of its length. Its type is
str, and it converts implicitly toc.str(§5.5) because the NUL is guaranteed. - A byte literal
b"..."is a view of static data, of typeconst u8[], with\xNNescapes and ASCII text; it is not NUL-terminated. Where a byte arrayu8[N]is expected it is that array, as the array literal of its bytes, and N must be its length:let magic: u8[4] = b"\x89PNG". - Triple-quoted strings drop a newline that directly follows the opening delimiter, strip indentation by the closing delimiter's column, and normalise CRLF to
\nbefore escapes are decoded. - Escapes in text are
\\,\",\',\n,\r,\t,\0, and\u{HEX}with one to six hex digits. There is no\xin text; it exists in byte literals. - A formatted string is not a value. It is consumed by
print, by aWriter, bystrings.format, or by a parameter of typefmt(§5.5).{{and}}are literal braces. Each field is{expression}, evaluated once, left to right, and is code rather than text: a string inside it is written with plain quotes,f"{name if name != "" else "none"}", and a backslash there is an error. A field may end with a format specification after a colon,{value:>8}or{mask:#x}, which lays the value out as Python'sformatdoes (§5.5).
Why. The one extra byte per literal means a literal can be passed to any C function that takes a char* without a copy, and most of them do.
4.5 Array literals#
let magic: u8[4] = [0x4c, 0x55, 0x43, 0x45]
let primes = [2, 3, 5, 7] # i64[4][...] is a fixed array whose length is its element count and whose element type comes from context or from the elements, which must agree. There are no list, map, or set literals in Base, because there are no built-in collections (§12.1).