Open timotheecour opened 4 years ago
The handling of break is broken. Let's call this newStyleIterator. If a newStyleIterator is called within an newStyleIterator the generating exception should NOT be caught. Furthermore, this implementation doesn't allow for newStyleIterators with optional arguments or a variable number of arguments. In addition there is no miterate.
The attached modification has following differences:
thanks, will look into it tmrw!
Finally, with the fantastic help from several people (especially on Gitter) I managed to fix your iterate macro. The idea is as follows:
the macro generates:
inc(StopIterateCount)
let StpItCount{.inject.} = StopIterateCount
try: ....
except StopIterate as EXC :
if EXC.Counter == StpItCount :
discard
else :
raise
Now, an original break breaks only the loop where it was coded.
This work with recursive calls of the iterator to itself. The identifiers StopIterateCount, StopIterate and StpItCount are changed in the real implementation s.t. these cannot be used by accident. iterates.nim.txt Perm.nim.txt
would fix:
TODO
check which other bugs would std/iterates fix; eg:
lent
doesn't work in iterators with tuple destructuring · Issue #14574 · nim-lang/Nimlinks