more examples
This commit is contained in:
parent
c5a843ea39
commit
9003149114
19 changed files with 287 additions and 0 deletions
52
tests/forp.ang
Normal file
52
tests/forp.ang
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
|
||||
fn range(from: int, to: int) -> (fn() -> (int, bool)) {
|
||||
i := from - 1
|
||||
|
||||
fn() -> (int, bool) {
|
||||
i = i + 1
|
||||
if i >= to {
|
||||
(-1, false)
|
||||
} else {
|
||||
(i, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i in range(0, 10) {
|
||||
println(i)
|
||||
}
|
||||
|
||||
fn chars(s: str) -> (fn() -> (str, bool)) {
|
||||
i := 0
|
||||
|
||||
fn() -> (str, bool) {
|
||||
if i >= s.length() {
|
||||
("", false)
|
||||
} else {
|
||||
c := s[i]
|
||||
i = i + 1
|
||||
|
||||
(c, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for c in chars("hello") {
|
||||
print(c)
|
||||
print(" ")
|
||||
}
|
||||
|
||||
println("")
|
||||
|
||||
fn items(l: [any]) -> (fn() -> (any, bool)) {
|
||||
i := 0
|
||||
|
||||
fn() -> (any, bool) {
|
||||
if i >= l.length() {
|
||||
(nil, false)
|
||||
} else {
|
||||
i = i + 1
|
||||
(l[i - 1], true)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue