On Thursday, 10 March 2016 at 17:59:21 UTC, Chris Wright wrote:
It's a little easier to write iterators in the Python style:
you don't have to cache the current value, and you don't have
to have a separate check for end-of-iteration. It's a little
easier to use them in the D style: you get more flexibility,
can check for emptiness without popping an item, and can grab
the first item several times.
I don't have any firm opinions on this, but escaping out of the
loop with an exception means you don't have to check for
emptiness. So I am not sure why D range-iterators should be
You can convert one to the other, so there's no theoretical
difference in what you can accomplish with them. It's mainly
annoying. A small efficiency concern, because throwing
exceptions is a little slow.
Efficiency of exceptions in Python is an implementation issue,
though. But I agree that the difference isn't all that
The largest practical difference comes when multiple functions
are interested in viewing the first item in the same range.
LL(1) parsers need to do this.
Iterators and generators in Python are mostly for for-loops and
comprehensions. In the rare case where you want lookahead you can
just write your own or use an adapter.
Of course, that's just looking at input ranges versus
iterators. If you look at other types of ranges, there's a lot
there that Python is missing.
Is there any work done on range-iterators and streams?