Luce Base
LuceEngineeringLuciaOS

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     -20i32

Underscores 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. A literal outside the contextual type's range is a compile error. A negative literal is unary minus applied to a positive literal, with the usual rule for the minimum signed value.

4.3 Floats#

1.0     6.022e23     0.5f32     1_000.25

Context 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 constants in the math module, not literals.

4.4 Characters and text#

'A'                          # one Unicode scalar: char
"hello"                      # UTF-8 text: str, static, NUL-terminated
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.
  • 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 to cstr (§5.5) because the NUL is guaranteed.
  • Triple-quoted strings strip indentation by the closing delimiter's column, and normalise CRLF to \n before escapes are decoded.
  • Escapes are \\, \", \', \n, \r, \t, \0, and \u{HEX}.
  • A formatted string is not a value. It is consumed by print, a Writer, or format_into (§5.5). {{ and }} are literal braces. Each field is an ordinary expression, evaluated once, left to right.

Why. The one extra byte per literal makes passing a literal to any C function that wants a char* free, which is most of them.

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).