Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Iterator APIs?

What I'm hoping to get out of the exercise is a sketch of what the various
options might end up looking like, and how they might be used (as well as
the effects on library design).

And then follow that up with some thoughts on semantics -- for example,
with iterators you can do some neat tricks if you disallow iterators
from escaping upwards; adjusting the base pointer without touching the
stack pointer will let you yeild from them with very little cost compared
to calling a function pointer.

On Tue, 24 Mar 2015 19:22:56 -0500
Ryan <rymg19@xxxxxxxxx> wrote:

> Although I kind of like Python's way best, my favorite is the Qt-way (I think).
> All iterators have two methods: a "done" method and a "next" method. The "next" method returns the next value, and the "done" method says whether or not the iterator is exhausted. Calling "next" on an empty iterator is undefined.
> There's also the half-STL-half-Qt way: same thing as described above, but with the C++ STL-style iterator types, the ability for a finished iterator (that is bidirectional) to go backwards, and an "end" function that returns a finished iterator. That would be a very, very powerful combo, but it would be a tad more complex than the Qt-way.
> C++'s iterator types are very useful in a statically-typed context, regardless of the inclusion of other STL-ish features.
> Having something like Python's generators along with this would be neat, too.
> Ori Bernstein <ori@xxxxxxxxxxxxxx> wrote:
> >So, I'm looking at how I want to handle custom iteration in for loops.
> >There
> >are a bunch of approaches out in the wild, and I'm trying to figure out
> >how I want
> >to have it done.
> >
> >Python has generators (https://www.python.org/dev/peps/pep-0255/)
> >C++ has iterators
> >(http://www.cs.northwestern.edu/~riesbeck/programming/c++/stl-iterators.html)
> >D has ranges (http://www.informit.com/articles/printerfriendly/1407357)
> >Common Lisp has the iterate module/macro/whatever
> >(https://common-lisp.net/project/iterate/doc/Don_0027t-Loop-Iterate.html)
> >
> >So, it's time for a gedanken experiment. What should iterating over
> >things look like, in
> >an ideal world with unicorns?
> -- 
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
> Check out my website: http://kirbyfan64.github.io/

Ori Bernstein <ori@xxxxxxxxxxxxxx>

Iterator APIs?Ori Bernstein <ori@xxxxxxxxxxxxxx>
Re: Iterator APIs?Ryan <rymg19@xxxxxxxxx>