diff options
author | Araq <rumpf_a@web.de> | 2012-11-15 08:45:16 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-11-15 08:45:16 +0100 |
commit | 1fada12a5f6a7af7cc22f49f02a9c63cef6ea130 (patch) | |
tree | 61a326d56d379f4ef8d91bca14df7b3b3ae5a7d2 /tests/run | |
parent | e4211230e8424d0522b3a827b8d1981ed22a22ed (diff) | |
download | Nim-1fada12a5f6a7af7cc22f49f02a9c63cef6ea130.tar.gz |
improvements for first class iterators
Diffstat (limited to 'tests/run')
-rw-r--r-- | tests/run/titer8.nim | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/run/titer8.nim b/tests/run/titer8.nim index ae82c7d3c..d77159353 100644 --- a/tests/run/titer8.nim +++ b/tests/run/titer8.nim @@ -1,6 +1,11 @@ discard """ output: '''tada -ta da''' +1 +2 +3 +ta da1 +2 +3''' """ # Test first class iterator: @@ -21,13 +26,26 @@ iterator tokenize2(s: string, seps: set[char] = Whitespace): tuple[ yield (substr(s, i, j-1), false) i = j +iterator count3(): int {.closure.} = + yield 1 + yield 2 + yield 3 + for word, isSep in tokenize2("ta da", whiteSpace): if not isSep: stdout.write(word) echo "" proc inProc() = + for c in count3(): + echo c + for word, isSep in tokenize2("ta da", whiteSpace): stdout.write(word) + for c in count3(): + echo c + + inProc() + |