← All examples

List literal family

A bare literal takes the family of its context, inside a list too: each value lands in an element slot.

list_literal_family.zg
# A bare literal takes the family of its context (types.md), inside a list too: each value lands in
# an element slot. `list.fill`'s value is the same. Here 1 and 2 are bins, 0.25 a deci64.
MAIN {
    let 'bs': list[bin64] = [1, 2];
    let 'more': list[bin64] = list.fill[value 1, count 3];
    let 'ds': list[deci64] = list.fill[value 0.25, count 3];
    std::print.stored['bs', newln];
    std::print.stored['more', newln];
    std::print.stored['ds', newln];
}
Output
[1, 2]
[1, 1, 1]
[0.25, 0.25, 0.25]