anglais/examples/list.ang

47 lines
600 B
Text

# Empty list
println([]any)
# List with items
println([3, 1, 4, 1, 5, 9, 2, 6, 5])
# List with items of different types
println(["", "私はかっこいいです。", true, nil, nil, 1, 2])
a := []int
a.push(1)
a.push(2)
println(a)
list := []int
x := 0
for n in 0..100 {
x = x + 2*n + 1
list.push(x)
}
println(list)
println(list.map(fn(a: int) -> int {
return a - 1
}))
println(list.length())
println(list.at(69))
other := []
for a in 0..=10 {
other = other.append(a)
}
sum := other.reduce(func(tot, x) {
return tot + x
}, 0)
println(sum)
assert(sum == a*(a-1)/2)