overload resolution for proc vars
This commit is contained in:
parent
36818817bd
commit
300430fbba
56 changed files with 2772 additions and 2430 deletions
|
|
@ -1,25 +1,26 @@
|
|||
# Test the closure implementation
|
||||
|
||||
proc map(n: var openarray[int], fn: proc (x: int): int {.closure}) =
|
||||
for i in 0..n.len-1:
|
||||
n[i] = fn(n[i])
|
||||
for i in 0..n.len-1: n[i] = fn(n[i])
|
||||
|
||||
proc foldr(n: openarray[int], fn: proc (x, y: int): int {.closure}): int =
|
||||
result = 0
|
||||
for i in 0..n.len-1:
|
||||
result = fn(result, n[i])
|
||||
|
||||
var
|
||||
myData: array[0..9, int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
myData: array[0..4, int] = [0, 1, 2, 3, 4]
|
||||
|
||||
proc testA() =
|
||||
var p = 0
|
||||
map(myData, lambda (x: int): int =
|
||||
result = x + 1 shl (lambda (y: int): int =
|
||||
return y + 1
|
||||
return y + p
|
||||
)(0)
|
||||
inc(p), 88)
|
||||
inc(p))
|
||||
|
||||
testA()
|
||||
for x in items(myData):
|
||||
echo x
|
||||
write(stout, x)
|
||||
#OUT 2 4 6 8 10
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue