fjgandrade / sharpkit

Automatically exported from code.google.com/p/sharpkit
0 stars 0 forks source link

Implement yield using a state machine #287

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Create an infinite sequence:

public static IEnumerable infinite()
{
  while (true)
    yield return 1;
}

The generated code will not terminate:

function infinite()
{
    var $yield = [];
    while (true)
    $yield.push(1);
    return $yield;
};

For the implementation details have a look at: 
http://blogs.msdn.com/b/oldnewthing/archive/2008/08/12/8849519.aspx

Original issue reported on code.google.com by steffen....@gmail.com on 10 Mar 2013 at 11:25

GoogleCodeExporter commented 9 years ago
Thanks, I'd love to add this feature, although it's a bit more tricky, since 
JavaScript does not have a 'goto' keyword, so the .NET implementation can't be 
used as/is. It has to be modified and adapted. The code you currently see is a 
simpler, pre-processed implementation, in which if you use yield, it will 
process the items immediatly (and not lazy), and return a list with the results.

Original comment by DanelK...@gmail.com on 17 May 2013 at 6:30