← All examples

List item context

A list literal's items take the list's element type as their context, as a declaration's value does: 0 minus.wrap 1 in a list[uint8] wraps at 8 bits, 2 shl 3 in a list[uint32]…

list_item_context.zg
# A list literal's items take the list's element type as their context, as a declaration's value
# does (owner, 2026-09-29: a): 0 minus.wrap 1 in a list[uint8] wraps at 8 bits, 2 shl 3 in a list[uint32]
# is a 32-bit shift, and bare numbers alone are still exact.
MAIN {
    let 'i': uint8 = 5;
    let 'xs': list[uint8] = [0 minus.wrap 1, 0 minus.wrap 'i', 250 plus.wrap 10];
    let 'ys': list[uint32] = [2 shl 3, not.bit 0];
    let 'zs': list[list[uint8]] = [[0 minus.wrap 2,], [1,]];
    let 'big': list[uint64] = [9692729768110883998 minus 3166240359165959856,];
    let 'inner' := copy 'zs'[pos 1];
    std::print.useful['xs'[pos 1], " ", 'xs'[pos 2], " ", 'xs'[pos 3], " ", 'ys'[pos 1], " ", 'ys'[pos 2], " ", 'inner'[pos 1], " ", 'big'[pos 1], newln];
}
Output
255 251 4 16 4294967295 254 6526489408944924142