Generators in D

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue May 17 08:28:00 PDT 2011


On 5/17/11 9:37 AM, Piotr Szturmaj wrote:
> Piotr Szturmaj wrote:
>> Hi,
>>
>> I've written some proof of concept code of generator pattern, example:
>>
>> void genSquares(out int result, int from, int to)
>> {
>> foreach (x; from .. to + 1)
>> {
>> yield!result(x * x);
>> }
>> }
>>
>> void main(string[] argv)
>> {
>> foreach (sqr; generator(&genSquares, 10, 20))
>> writeln(sqr);
>> }
>>
>> posted on github:
>>
>> https://github.com/pszturmaj/dgenerators
>>
>> Thanks to Sean Kelly who wrote Fiber code.
>>
>> Piotr
>
> Well, I've just found this:
> http://www.mail-archive.com/digitalmars-d@puremagic.com/msg30204.html.
> It seems someone did it before ;)

That's why it's important to follow through with a formal submission to 
Phobos.

> In regards to serializable fibers, I've found some interesting potential
> usage - session handling in HTTP server. Fiber code could represent
> session and could be saved to disk in the middle of execution, just like
> sessions are saved in PHP. This is used to offload memory when handling
> great number of sessions.
>
> If serialization will be clever enough, these fibers could even be
> shared across different servers! This is really a requirement in load
> balanced environments.

Sounds very interesting!


Andrei


More information about the Digitalmars-d mailing list