First draft of procs complete
This commit is contained in:
parent
8b3a86730a
commit
b0babe2090
1 changed files with 17 additions and 2 deletions
|
|
@ -63,6 +63,21 @@ proc `^&*^@%`(a, b: string): string =
|
|||
assert("foo" ^&*^@% "bar" == "fr")
|
||||
```
|
||||
|
||||
## Generic Functions
|
||||
|
||||
- operators
|
||||
- generics
|
||||
<!-- XXX Needs own section -->
|
||||
Generic functions are like C++'s templates and allow for the same statically checked duck-typing semantics as templates.
|
||||
|
||||
``` nimrod
|
||||
# Not really good idea for obvious reasons
|
||||
let zero = ""
|
||||
proc `+`(a, b: string): string =
|
||||
a & b
|
||||
|
||||
proc `*`[T, I](a: T, b: int): T =
|
||||
result = zero
|
||||
for i in 0..b:
|
||||
result = result + a
|
||||
|
||||
assert("a" * 10 == "aaaaaaaaaaa")
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue