Update and add examples
This commit is contained in:
parent
40a538b73d
commit
74bd9c9582
4 changed files with 79 additions and 2 deletions
51
examples/list.ang
Normal file
51
examples/list.ang
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue