C# has generator functions which have syntax like:
IEnumerable<int> GetNats(int max)
{
for (int i=0; i < max; ++i)
yield return i;
}
A feature I am interested in for my programming language (a simple object-oriented programming similar to Java, Scala, ActionScript, and C#) are generator expressions. These are essentially syntactic sugar for generator functions.
My current favorite candidate is the following syntax:
IEnumerable<int> nats =
witheach (i in range(0, 42))
yield i * 2;
The expression range(0, 42)
is a built-in generator function.
So my question is what syntax would you prefer to see for generator expressions, in a C#/Java/Scala/ActionScript type language, and why?
Some factors that may influence responses are that like Scala and ActionScript, types in my language are declared after the type. For example:
var myVar : SomeType = initialValue;
Also anonymous functions look like this:
var myFunc = function(int x) {
return x + 1;
}
Other than that the rest of my language syntax resembles Java or C#. My language has a foreach
statement which is very similar to C#.