Update and add examples

This commit is contained in:
Neemek 2025-03-10 16:24:37 +01:00
parent 40a538b73d
commit 74bd9c9582
Signed by: neemek
GPG key ID: 28360A8951CD0E9B
4 changed files with 79 additions and 2 deletions

51
examples/list.ang Normal file
View file

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