timotheecour / Nim

Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
http://nim-lang.org/
Other
2 stars 0 forks source link

library defined iterators #378

Open timotheecour opened 3 years ago

timotheecour commented 3 years ago

would fix:

TODO

check which other bugs would std/iterates fix; eg:

links

HJarausch commented 3 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:

  1. it defines and uses StopIterate instead of IterateError
  2. the generated call to the newStyleIterator uses the keyword parameter Yield
  3. it defines 4 macros: iterate, miterate, riterate and rmiterate.

iterates.nim.txt Perm.nim.txt

timotheecour commented 3 years ago

thanks, will look into it tmrw!

HJarausch commented 3 years ago

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:

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