Updated the manual and changed the syntax for foreach loops
This commit is contained in:
parent
67b44dbfc9
commit
cc49cb98a6
|
@ -57,7 +57,7 @@ __Note__: Peon supports [name stropping](https://en.wikipedia.org/wiki/Stropping
|
|||
|
||||
```
|
||||
fn fib(n: int): int {
|
||||
if (n < 3) {
|
||||
if n < 3 {
|
||||
return n;
|
||||
}
|
||||
return fib(n - 1) + fib(n - 2);
|
||||
|
@ -109,7 +109,7 @@ __Note__: Code the likes of `a.b()` is desugared to `b(a)` if there exists a fun
|
|||
### Generic declarations
|
||||
|
||||
```
|
||||
fn genericSum[T](a, b: T): T { # Note: "a, b: T" means that both a and b are of type T
|
||||
fn genericSum[T: Number](a, b: T): T { # Note: "a, b: T" means that both a and b are of type T
|
||||
return a + b;
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ genericSum(1'u8, 250'u8);
|
|||
#### Multiple generics
|
||||
|
||||
```
|
||||
fn genericSth[T, K](a: T, b: K) { # Note: no return type == void function!
|
||||
fn genericSth[T: someInterface, K: someInterface2](a: T, b: K) { # Note: no return type == void function!
|
||||
# code...
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ fn someF: int {
|
|||
|
||||
```
|
||||
generator count(n: int): int {
|
||||
while (n > 0) {
|
||||
while n > 0 {
|
||||
yield n;
|
||||
n -= 1;
|
||||
}
|
||||
|
@ -175,12 +175,13 @@ coroutine req(url: string): string {
|
|||
|
||||
coroutine main(urls: list[string]) {
|
||||
pool = concur.pool(); # Creates a task pool: like a nursery in njsmith's article
|
||||
for (var i = 0; i < urls.len(); i += 1) {
|
||||
pool.spawn(req, urls[i]);
|
||||
foreach url in urls {
|
||||
pool.spawn(req, urls);
|
||||
}
|
||||
# The pool has internal machinery that makes the parent
|
||||
# task wait until all child exit! When this function
|
||||
# returns, ALL child tasks will have exited somehow
|
||||
# returns, ALL child tasks will have exited somehow.
|
||||
# Exceptions and return values propagate neatly, too.
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -655,7 +655,7 @@ proc forEachStmt(self: Parser): Statement =
|
|||
self.currentLoop = Loop
|
||||
self.expect(Identifier)
|
||||
let identifier = newIdentExpr(self.peek(-1), self.scopeDepth)
|
||||
self.expect(":")
|
||||
self.expect("in")
|
||||
let expression = self.expression()
|
||||
self.expect(LeftBrace)
|
||||
result = newForEachStmt(identifier, expression, self.blockStmt(), tok)
|
||||
|
|
Loading…
Reference in New Issue