Updated manual
This commit is contained in:
parent
3a48999a35
commit
cc5622605d
|
@ -117,7 +117,7 @@ operator `+`(a, b: Foo): Foo {
|
|||
Foo(fieldOne: 1, fieldTwo: 3) + Foo(fieldOne: 2, fieldTwo: 3); # Foo(fieldOne: 3, fieldTwo: 6)
|
||||
```
|
||||
|
||||
__Note__: Custom operators (e.g. `foo`) can also be defined! The backticks around the plus sign serve to mark it
|
||||
__Note__: Custom operators (e.g. `foo`) can also be defined. The backticks around the plus sign serve to mark it
|
||||
as an identifier instead of a symbol (which is a requirement for function names, since operators are basically
|
||||
functions in peon). In fact, even the built-in peon operators are implemented partially in peon (actually, just
|
||||
their stubs are) and they are then specialized in the compiler to get rid of unnecessary function call overhead.
|
||||
|
@ -169,7 +169,7 @@ fn add[T: any](a, b: T): T {
|
|||
|
||||
While the intent of this code is clear and makes sense semantically speaking, peon will refuse
|
||||
to compile it because it cannot prove that the `+` operator is defined on every type (in fact,
|
||||
it's only defined for numbers): this is a feature! If peon allowed it, `any` could be used to
|
||||
it's only defined for numbers): this is a feature. If peon allowed it, `any` could be used to
|
||||
escape the safety of the type system (for example, calling `add` with `string`s, which may or
|
||||
may not be what you want).
|
||||
|
||||
|
@ -226,7 +226,7 @@ genericSth(1, 3.0);
|
|||
```
|
||||
|
||||
|
||||
#### Even more generics (TODO)
|
||||
#### Even more generics
|
||||
|
||||
```
|
||||
type Box*[T: Number] = object {
|
||||
|
@ -238,26 +238,26 @@ var boxInt = Box[int](1);
|
|||
```
|
||||
|
||||
__Note__: The `*` modifier to make a name visible outside the current module must be put
|
||||
__before__ generics declarations, so only `fn foo*[T](a: T) {}` is the correct syntax
|
||||
__before__ the generic constraints, so only `fn foo*[T](a: T) {}` is the correct syntax.
|
||||
|
||||
|
||||
|
||||
### Forward declarations
|
||||
|
||||
```
|
||||
fn someF: int; # Semicolon, no body!
|
||||
fn someF: int; # Semicolon and no body == forward declaration
|
||||
|
||||
print(someF()); # This works!
|
||||
print(someF()); # Prints 42
|
||||
|
||||
fn someF: int {
|
||||
return 42;
|
||||
}
|
||||
```
|
||||
|
||||
__Note__: A function that is forward-declared __must__ be implemented in the same
|
||||
module as the forward declaration
|
||||
__Note__: A function that is forward-declared __must__ be implemented in the same module as
|
||||
the forward declaration.
|
||||
|
||||
### Generators (TODO)
|
||||
### Generators
|
||||
|
||||
```
|
||||
generator count(n: int): int {
|
||||
|
@ -267,13 +267,13 @@ generator count(n: int): int {
|
|||
}
|
||||
}
|
||||
|
||||
foreach (n: count(10)) {
|
||||
foreach n in count(10) {
|
||||
print(n);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Coroutines (TODO)
|
||||
### Coroutines
|
||||
|
||||
```
|
||||
import concur;
|
||||
|
|
Loading…
Reference in New Issue