Luce
Luce BaseSourceLuciaOS

3. Literals

3.1 Boolean and absence#

true, false, and none. none takes its optional type from context and is never a universal null.

3.2 Numbers#

let count = 42
let mask = 1_000_000
let hex = 0xFF
let ratio = 0.5
let large = 6.022e23

An integer literal is an int and a literal with a point or an exponent is a float. There are no suffixes and no other widths. Underscores separate digits; based prefixes 0x, 0o and 0b are lowercase. A literal outside its type's range is a compile error. - before a literal is negation, and -9223372036854775808 is accepted.

3.3 Text and bytes#

let name = "Ada"
let path = r"C:\temp"
let greeting = f"hello {name}, you are {age + 1}"
let block = """
    two lines
    of text
    """
let data = b"\x00\x01"

A str literal is UTF-8 with the escapes \\ \" \n \r \t \0 \u{HEX}. A raw literal r"..." has no escapes. A formatted literal f"..." interpolates any expression whose type has a display (§10.5); a format spec after : is not part of the language and a { is written {{. A field's expression holds no brace of its own: a set or map literal is bound to a name first. A triple-quoted literal strips the common indentation of its lines. A bytes literal b"..." admits \xNN and is the only place a byte is spelled.

There is no character literal: a text of one scalar is a str of length one.

3.4 Collections#

let primes = [2, 3, 5, 7]
let ages = {"Ada": 36, "Grace": 45}
let seen = {1, 2, 3}
let empty_map: map[str, int] = {}
let empty_list: list[str] = []

[...] is a list, {k: v, ...} a map, {v, ...} a set; {} is an empty map. The element type comes from context or from the elements, which must agree. A literal creates a new collection each time it is evaluated.

3.5 Tuples#

(1, "one") is a tuple; (1,) is a tuple of one; () is unit.