diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-04-20 14:33:44 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-04-20 14:33:44 +0100 |
commit | 232d2528859f7eb6a47bdc274bcba67c8fdaedff (patch) | |
tree | ed01daa2986ee65c80767398b00b4ec060dc625a /tests | |
parent | cf3b54fdcb2a3a5f7a061632c8f9156fa9cddbb4 (diff) | |
download | Nim-232d2528859f7eb6a47bdc274bcba67c8fdaedff.tar.gz |
Added new future module with a closure macro.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/closure/tclosuremacro.nim | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/closure/tclosuremacro.nim b/tests/closure/tclosuremacro.nim new file mode 100644 index 000000000..80d89a090 --- /dev/null +++ b/tests/closure/tclosuremacro.nim @@ -0,0 +1,43 @@ +discard """ + output: '''10 +10 +10 +3 +3 +noReturn +''' +""" + +import future + +when false: + proc twoParams(x: (int, int) -> int): int = + result = x(5, 5) + + proc oneParam(x: int -> int): int = + x(5) + + proc noParams(x: () -> int): int = + result = x() + + proc noReturn(x: () -> void) = + x() + + proc doWithOneAndTwo(f: (int, int) -> int): int = + f(1,2) + + echo twoParams(proc (a, b): auto = a + b) + echo twoParams((x, y) => x + y) + + echo oneParam(x => x+5) + + echo noParams(() => 3) + + echo doWithOneAndTwo((x, y) => x + y) + + noReturn(() -> void => echo("noReturn")) + +proc pass2(f: (int, int) -> int): (int) -> int = + (x: int) -> int => f(2, x) + +#echo pass2((x, y) => x + y) |