Tangent: Yield, part 1

Published January 10, 2009
Advertisement
Not much Tangent work recently. Recouping from work fires and rebuilding social currency. Tonight though I got a little work in, moving along to the yield keyword/behavior now that iterators work. I added behavior to the block code to allow the yield behavior rather than requiring the method get reset each time; actually rather trivial based on how it was implemented.

I also modified the syntax for methods (and anonymous methods) to not just take a type expression as a return type. The syntax now allows for yields< type-exp > there. The method still returns IEnumerable like C# generators, but it's a little more explicit about what is going on (and happens to make my life easier since I don't have to inspect the entire method body to know if I need to generate the anonymous enumerable or not).

Also, I'm looking to make yield return X into simply yield X. I've not decided yet if I need/want yield break but will probably make return(); do that behavior if desired. So, example expected implementation:

public static yields    from (int i) to infinity{    while(true){        yield i;        i++;    }}for each from 0 to infinity do (int x)=>void{ print x; };


And hopefully getting some type inference or perhaps making no lambda return type mean void return to make the end a little less verbose.
0 likes 1 comments

Comments

Jotaf
Hey that's pretty cool [grin]

The ability to write iterators like that is simple and concise, I like it.

However, the ability I'd look forward the most with yield, applied to game scripting, would be to avoid state-machines and simply write procedural code sprinkled with some yields.[wink]
January 11, 2009 11:28 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement