diff options
author | Araq <rumpf_a@web.de> | 2012-06-19 22:37:00 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-06-19 22:37:00 +0200 |
commit | f191059e56ccf8accf872f4fb10986418dac45e2 (patch) | |
tree | aafd9edc964744fd82b832660f2bcf36967cd309 /tests/run | |
parent | 98458a3076c5d4fc2942cbd3e260999d1adcfe9a (diff) | |
download | Nim-f191059e56ccf8accf872f4fb10986418dac45e2.tar.gz |
somewhat working closures
Diffstat (limited to 'tests/run')
-rw-r--r-- | tests/run/tclosure2.nim | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/tests/run/tclosure2.nim b/tests/run/tclosure2.nim index 5a1cb8075..113c98250 100644 --- a/tests/run/tclosure2.nim +++ b/tests/run/tclosure2.nim @@ -1,20 +1,30 @@ discard """ - output: '''1 + output: '''0 +11 +1 +11 2 +11 3 +11 4 +11 5 +11 6 +11 7 +11 8 -9 -10 11 +9 11 py py py -py''' +py +px +6''' """ when true: @@ -34,7 +44,7 @@ when true: ax() -when false: +when true: proc accumulator(start: int): (proc(): int {.closure.}) = var x = start-1 #let dummy = proc = @@ -62,8 +72,14 @@ when false: outer() -when false: - proc outer = +when true: + proc outer2 = + var errorValue = 3 + proc fac[T](n: T): T = + if n < 0: result = errorValue + elif n <= 1: result = 1 + else: result = n * fac(n-1) + proc px() {.closure.} = echo "px" @@ -76,7 +92,9 @@ when false: "xyz": py } mapping[0][1]() + + echo fac(3) - outer() + outer2() |