Iterator-producing function in Nim: works when assigning the iterator, stuck when calling it directly
问题 I tried to make a procedure that creates an iterator, as follows: proc makeCDFrom(start: int): iterator(): int = result = iterator(): int = var i: int = start while i >= 0: echo "i:", i yield(i) dec(i) let cdFrom6 = makeCDFrom(6) for j in cdFrom6(): echo "j:", j This appears to work as expected: i:6 j:6 i:5 j:5 i:4 j:4 i:3 j:3 i:2 j:2 i:1 j:1 i:0 j:0 However, initially, I had tried with this slight variation: proc makeCDFrom(start: int): iterator(): int = result = iterator(): int = var i: int