Re: Generators in D

2011-05-19 Thread Piotr Szturmaj
Sean Kelly wrote: On May 18, 2011, at 5:21 PM, Piotr Szturmaj wrote: Jose Armando Garcia wrote: If serialization will be clever enough, these fibers could even be shared across different servers! This is really a requirement in load balanced environments. A very old research paper (I think

Re: Generators in D

2011-05-19 Thread Piotr Szturmaj
Sean Kelly wrote: On May 18, 2011, at 5:07 PM, Piotr Szturmaj wrote: Sean Kelly wrote: On May 18, 2011, at 8:00 AM, Piotr Szturmaj wrote: Sean Kelly wrote: On May 17, 2011, at 2:37 PM, Piotr Szturmaj wrote: But couldn't Fiber's stack be scanned for references to itself and readjusted?

Re: Generators in D

2011-05-18 Thread Sean Kelly
On May 18, 2011, at 5:21 PM, Piotr Szturmaj wrote: > Jose Armando Garcia wrote: >>> >>> If serialization will be clever enough, these fibers could even be shared >>> across different servers! This is really a requirement in load balanced >>> environments. >>> >> >> A very old research paper (I

Re: Generators in D

2011-05-18 Thread Sean Kelly
On May 18, 2011, at 5:07 PM, Piotr Szturmaj wrote: > Sean Kelly wrote: >> >> On May 18, 2011, at 8:00 AM, Piotr Szturmaj wrote: >> >>> Sean Kelly wrote: On May 17, 2011, at 2:37 PM, Piotr Szturmaj wrote: > > But couldn't Fiber's stack be scanned for references to itself and >

Re: Generators in D

2011-05-18 Thread Piotr Szturmaj
Jose Armando Garcia wrote: If serialization will be clever enough, these fibers could even be shared across different servers! This is really a requirement in load balanced environments. A very old research paper (I think it was for the amoeba project) wrote a long time ago (I don't remember

Re: Generators in D

2011-05-18 Thread Piotr Szturmaj
Sean Kelly wrote: On May 18, 2011, at 8:00 AM, Piotr Szturmaj wrote: Sean Kelly wrote: On May 17, 2011, at 2:37 PM, Piotr Szturmaj wrote: But couldn't Fiber's stack be scanned for references to itself and readjusted? Without type information, there's no way to be sure that something is ac

Re: Generators in D

2011-05-18 Thread Sean Kelly
On May 18, 2011, at 8:00 AM, Piotr Szturmaj wrote: > Sean Kelly wrote: >> On May 17, 2011, at 2:37 PM, Piotr Szturmaj wrote: >>> >>> But couldn't Fiber's stack be scanned for references to itself and >>> readjusted? >> >> Without type information, there's no way to be sure that something is >

Re: Generators in D

2011-05-18 Thread Piotr Szturmaj
Sean Kelly wrote: On May 17, 2011, at 2:37 PM, Piotr Szturmaj wrote: Sean Kelly wrote: On May 11, 2011, at 3:06 PM, Piotr Szturmaj wrote: Andrei Alexandrescu wrote: * can you implement save() to make this a forward range (e.g. by creating a new fiber that has its own state)? It is not tha

Re: Generators in D

2011-05-17 Thread Sean Kelly
On May 17, 2011, at 2:37 PM, Piotr Szturmaj wrote: > Sean Kelly wrote: >> On May 11, 2011, at 3:06 PM, Piotr Szturmaj wrote: >> >>> Andrei Alexandrescu wrote: * can you implement save() to make this a forward range (e.g. by creating a new fiber that has its own state)? >>> >>> It is no

Re: Generators in D

2011-05-17 Thread Piotr Szturmaj
Sean Kelly wrote: On May 17, 2011, at 7:37 AM, Piotr Szturmaj wrote: 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

Re: Generators in D

2011-05-17 Thread Piotr Szturmaj
Sean Kelly wrote: On May 11, 2011, at 3:06 PM, Piotr Szturmaj wrote: Andrei Alexandrescu wrote: * can you implement save() to make this a forward range (e.g. by creating a new fiber that has its own state)? It is not that simple I guess. Fiber class doesn't give any opportunity to save >> cu

Re: Generators in D

2011-05-17 Thread Sean Kelly
On May 17, 2011, at 7:37 AM, Piotr Szturmaj wrote: > > 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 i

Re: Generators in D

2011-05-17 Thread Sean Kelly
On May 11, 2011, at 3:06 PM, Piotr Szturmaj wrote: > Andrei Alexandrescu wrote: >> * can you implement save() to make this a forward range (e.g. by >> creating a new fiber that has its own state)? > > It is not that simple I guess. Fiber class doesn't give any opportunity to > save current stack

Re: Generators in D

2011-05-17 Thread Sean Kelly
On May 11, 2011, at 3:09 PM, Piotr Szturmaj wrote: > %u wrote: >> On 05/10/2011 07:06 PM, Piotr Szturmaj wrote: >>> I forgot to ask. Any comments or suggestions? >> >> This is **beast**. >> >> Just one thing: Would it work correctly if I was using fibers in my >> own code? > > I don't know. If

Re: Generators in D

2011-05-17 Thread Jose Armando Garcia
> > If serialization will be clever enough, these fibers could even be shared > across different servers! This is really a requirement in load balanced > environments. > A very old research paper (I think it was for the amoeba project) wrote a long time ago (I don't remember the wording) that is u

Re: Generators in D

2011-05-17 Thread Andrei Alexandrescu
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; genera

Re: Generators in D

2011-05-17 Thread Piotr Szturmaj
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); }

Re: Generators in D

2011-05-12 Thread so
The argument is an alias, so just a symbol. See: http://digitalmars.com/d/2.0/template.html (Template Alias Arguments) The trick is that the template is instantiated as a local function, which has access to the enclosing scope. (and therewith to the local symbol that is aliased) Timon

Re: Generators in D

2011-05-12 Thread Timon Gehr
> > void genSquares(out int result, int from, int to) > > yield!result(x * x); > > Wow! i had no idea about this feature! (Variables as template parameters) > Do we have any documentation, usage example (anything!)? Pretty please. The argument is an alias, so just a symbol. See: http://d

Re: Generators in D

2011-05-12 Thread so
void genSquares(out int result, int from, int to) yield!result(x * x); Wow! i had no idea about this feature! (Variables as template parameters) Do we have any documentation, usage example (anything!)? Pretty please.

Re: Generators in D

2011-05-11 Thread Andrei Alexandrescu
On 5/11/11 5:09 PM, Piotr Szturmaj wrote: %u wrote: On 05/10/2011 07:06 PM, Piotr Szturmaj wrote: I forgot to ask. Any comments or suggestions? This is **beast**. Just one thing: Would it work correctly if I was using fibers in my own code? I don't know. If fibers may call other fibers the

Re: Generators in D

2011-05-11 Thread KennyTM~
On May 12, 11 06:06, Piotr Szturmaj wrote: I have seen this many times in the library, example from std.traits: template ReturnType(/+@@@BUG4217@@@+/func...) if (/+@@@BUG4333@@@+/staticLength!(func) == 1) And I realized that as a good idea, because bug 4333 is not closed yet. I don't thi

Re: Generators in D

2011-05-11 Thread Piotr Szturmaj
KennyTM~ wrote: On May 11, 11 08:06, Piotr Szturmaj wrote: I forgot to ask. Any comments or suggestions? The argument match assertion is too strict. The following does not compile: --- void main() { auto a = generator( (out int result, double e) { yield!result(1); }, 4); writeln(a

Re: Generators in D

2011-05-11 Thread Piotr Szturmaj
%u wrote: On 05/10/2011 07:06 PM, Piotr Szturmaj wrote: I forgot to ask. Any comments or suggestions? This is **beast**. Just one thing: Would it work correctly if I was using fibers in my own code? I don't know. If fibers may call other fibers then it should work.

Re: Generators in D

2011-05-11 Thread Piotr Szturmaj
Andrei Alexandrescu wrote: On 05/10/2011 07:06 PM, Piotr Szturmaj wrote: I forgot to ask. Any comments or suggestions? This is solid work, and very interesting. I wonder how we can integrate it best with Phobos (e.g. put in its own module vs. integrating into std.range). This code is very sh

Re: Generators in D

2011-05-11 Thread KennyTM~
On May 11, 11 08:06, Piotr Szturmaj wrote: I forgot to ask. Any comments or suggestions? The argument match assertion is too strict. The following does not compile: --- void main() { auto a = generator( (out int result, double e) { yield!result(1); }, 4); writel

Re: Generators in D

2011-05-11 Thread %u
On 05/10/2011 07:06 PM, Piotr Szturmaj wrote: > I forgot to ask. Any comments or suggestions? This is **beast**. Just one thing: Would it work correctly if I was using fibers in my own code?

Re: Generators in D

2011-05-11 Thread Andrei Alexandrescu
On 05/10/2011 07:06 PM, Piotr Szturmaj wrote: I forgot to ask. Any comments or suggestions? This is solid work, and very interesting. I wonder how we can integrate it best with Phobos (e.g. put in its own module vs. integrating into std.range). I suggest you write an article about this arti

Re: Generators in D

2011-05-10 Thread Piotr Szturmaj
I forgot to ask. Any comments or suggestions?

Generators in D

2011-05-10 Thread Piotr Szturmaj
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(