Add set index in list, and update lib+examples+tests
This commit is contained in:
parent
8d12c0bdf8
commit
0f905a7fea
12 changed files with 117 additions and 60 deletions
|
|
@ -3,14 +3,9 @@
|
|||
|
||||
fn range(from: int, to: int) -> (fn() -> (int, bool)) {
|
||||
i := from - 1
|
||||
end := to - 1
|
||||
|
||||
fn() -> (int, bool) {
|
||||
if i < end {
|
||||
(i = i+1, true)
|
||||
} else {
|
||||
(-1, false)
|
||||
}
|
||||
(i = i+1, i+1 < to)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
# Empty list
|
||||
println([])
|
||||
println([]any)
|
||||
|
||||
# List with items
|
||||
println([3, 1, 4, 1, 5, 9, 2, 6, 5])
|
||||
|
|
@ -8,25 +8,25 @@ println([3, 1, 4, 1, 5, 9, 2, 6, 5])
|
|||
# List with items of different types
|
||||
println(["", "私はかっこいいです。", true, nil, nil, 1, 2])
|
||||
|
||||
a := []
|
||||
a := []int
|
||||
|
||||
a = a + [1]
|
||||
a = a + [2]
|
||||
a.push(1)
|
||||
a.push(2)
|
||||
|
||||
println(a)
|
||||
|
||||
|
||||
list := []
|
||||
list := []int
|
||||
|
||||
x := 0
|
||||
for n in 0..100 {
|
||||
x = x + 2*n + 1
|
||||
|
||||
list = list + [x]
|
||||
list.push(x)
|
||||
}
|
||||
|
||||
println(list)
|
||||
println(list.map(func(a) {
|
||||
println(list.map(fn(a: int) -> int {
|
||||
return a - 1
|
||||
}))
|
||||
println(list.length())
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
# This program computes the fibonacci numbers using recursion (O(2^n))
|
||||
# It is very slow
|
||||
func fib(x: number) number {
|
||||
fn fib(x: number) number {
|
||||
if x <= 1 {
|
||||
return x
|
||||
x
|
||||
} else {
|
||||
fib(x - 1) + fib(x - 2)
|
||||
}
|
||||
return fib(x - 1) + fib(x - 2)
|
||||
}
|
||||
|
||||
n := 0
|
||||
while n < 100 {
|
||||
write(str(fib(n)))
|
||||
println(fib(n))
|
||||
n = n + 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue