yield iteration
bearophile
bearophileHUGS at lycos.com
Sun Jul 29 06:53:00 PDT 2012
anonymous:
> A subthread of the "Impressed" thread revolved around D's lack
> of a yield mechanism for iteration.
The yield as in Python is so useful and handy, and I miss it
often in D.
This is an example of Inverse Gray iterator (Sloane series
A006068) Python2 code from:
http://code.activestate.com/recipes/221457/
def A006068():
yield 0
for x in A006068():
if x & 1:
yield 2 * x + 1
yield 2 * x
else:
if x:
yield 2 * x
yield 2 * x + 1
Turning that in D code that uses opApply is not hard, but the
code inflates 3X, and you can't use most std.algorithm on it.
I have discussed the situation a little here:
http://d.puremagic.com/issues/show_bug.cgi?id=5660
Bye,
bearophile
More information about the Digitalmars-d
mailing list