Jonathan M Davis:

And given how useless pure input ranges are, I really don't see much value in that. About all they give you is the ability to iterate over a set of values once. The other range types are _far_ more powerful, and pure input ranges
should be avoided as much as possible IMHO.

Python generators are essentially input ranges, you can go only forward, and they yield their results only once:


g = (i ** 2 for i in xrange(5))
list(g)
[0, 1, 4, 9, 16]
list(g)
[]
def gen():
...     for i in xrange(5):
...         yield i * i
...
g = gen()
list(g)
[0, 1, 4, 9, 16]
list(g)
[]


Yet in Python they are used everywhere. I define input ranges often in D and I think they are useful.

Having a built-in "yield" in a language is quite handy. Take a look at the Python and the second D solutions here:
http://rosettacode.org/wiki/Same_Fringe

Bye,
bearophile

Reply via email to