-
Notifications
You must be signed in to change notification settings - Fork 23
Closed as not planned
Labels
Description
Problem
Iterator syntax as currently implemented leaves a lot to be desired.
As seen in this forum post, there are couple of problems with current syntax:
- instantiating iterators with
let x = fibo(without()and without parameters) - calling the existing iterator with parameters which might (
(1, 1)at the first call) or might not ((10, 20),(100, 999)) have anything to do with the current iterator - wrapping iterator inside of a proc helps a bit regarding a better-looking syntax when calling the existing iterator
Proposal:
Use next to call the existing iterator. (Similar to other languages, e.g. Python)
iterator fibo(a, b: int): int = #1: some pragma here?
var
a = a
b = b
while true:
yield a
(a, b) = (b, a+b)
let #2: instatiating iterators with their starting parameters
x = fibo(1, 1)
y = fibo(34, 55)
for _ in 1 .. 5:
echo next(x) #3: calling the existing iterator `x` - cannot pass any new parameter once the iterator is instatiated
echo next(y) #4: first call of `y`