Jump to content
  • Advertisement
  • entries
    359
  • comments
    237
  • views
    189396

Tangent: Yield, part 1

Sign in to follow this  
Telastyn

90 views

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.
Sign in to follow this  


1 Comment


Recommended Comments

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]

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!