Any python-like generator patterns in D?

Ali Çehreli acehreli at yahoo.com
Thu Sep 8 10:47:55 PDT 2011


On Thu, 08 Sep 2011 13:35:02 +0200, Samuel Lampa wrote:

> Hi,
> 
> I found these slides very interesting, on how python generator patterns
> can be used to create re-usable code-parts that can be "piped" togegher
> ad infinitum, to create e.g. parsing pipelines requiring minimal memory
> (things a sysadmin working with huge files might need quite often):
> 
> http://www.dabeaz.com/generators/index.html PDF:
> http://www.dabeaz.com/generators/Generators.pdf
> 
> It would be nice to do this kind of stuff in D though, to hopefully gain
> some performance, so I wonder, is there similar stuff in D, and where to
> find info about it?
> 
> Cheers,
> Samuel

D uses the range concept. Phobos ranges are based on the ideas presented 
in this article:

  http://www.informit.com/articles/printerfriendly.aspx?p=1407357

But some of the design and even the names of range types have changed 
since that article has been written.

These and other Phobos modules make use of ranges:

  http://www.d-programming-language.org/phobos/std_range.html

  http://www.d-programming-language.org/phobos/std_algorithm.html

  http://www.d-programming-language.org/phobos/std_array.html

Ali

P.S. I am in the process of translating my Turkish D book to English. For 
completeness, here are the two chapters about ranges:

  http://ddili.org/ders/d/araliklar.html

  http://ddili.org/ders/d/araliklar_baska.html


More information about the Digitalmars-d-learn mailing list