Open
Description
originally reported here: https://github.com/nim-lang/Nim/issues/7047#issuecomment-390604711
proc iterGen(someEvalOnceArg: int): (iterator (): int {.closure.}) =
result = iterator (): int =
yield 1
yield 2
yield 3
# this works fine
let it = iterGen(42)
for x in it():
echo x
# this is an infinite loop
for x in iterGen(42)():
echo x
proposal
- make
for x in expr: ...
cache the value ofexpr
to avoid this (maybe using something likesequtils.evalOnceAs
)
scratch below
- maybe
for
could be actually implemented in system.nim, now that we haveforLoopMacros
; maybe this would help in solving this (not sure)
Metadata
Metadata
Assignees
Labels
No labels