anglais/examples/list.ang

47 lines
590 B
Text

# Empty list
println([])
# 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 := []
a = a + [1]
a = a + [2]
println(a)
list := []
x := 0
for n in 0..100 {
x = x + 2*n + 1
list = list + [x]
}
println(list)
println(list.map(func(a) {
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)