diff options
author | Araq <rumpf_a@web.de> | 2012-11-15 22:54:06 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-11-15 22:54:06 +0100 |
commit | 7a2c11d3cfef74eaf55ab27adbb1748a04d7904f (patch) | |
tree | 9a36f7458eb694c26aa8a4aee22377c20a65703e /tests/run/titer8.nim | |
parent | 1fada12a5f6a7af7cc22f49f02a9c63cef6ea130 (diff) | |
download | Nim-7a2c11d3cfef74eaf55ab27adbb1748a04d7904f.tar.gz |
next steps for first class iterators
Diffstat (limited to 'tests/run/titer8.nim')
-rw-r--r-- | tests/run/titer8.nim | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/tests/run/titer8.nim b/tests/run/titer8.nim index d77159353..e0de6a6b0 100644 --- a/tests/run/titer8.nim +++ b/tests/run/titer8.nim @@ -3,9 +3,18 @@ discard """ 1 2 3 -ta da1 -2 -3''' +ta da1 1 +1 2 +1 3 +2 1 +2 2 +2 3 +3 1 +3 2 +3 3 +0 +1 +2''' """ # Test first class iterator: @@ -44,8 +53,27 @@ proc inProc() = stdout.write(word) for c in count3(): - echo c + for d in count3(): + echo c, " ", d inProc() +iterator count0(): int {.closure.} = + # note: doesn't require anything in its closure (except 'state') + yield 0 + +iterator count2(): int {.closure.} = + # note: requires 'x' in its closure + var x = 1 + yield x + inc x + yield x + +# a first class iterator has the type 'proc {.closure.}', but maybe +# it shouldn't: +proc invoke(iter: proc(): int {.closure.}) = + for x in iter(): echo x + +invoke(count0) +invoke(count2) |