🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tangent: Yield, part 4

Published January 27, 2009
Advertisement
Tonight I had a tiny bit of spare time to devote to tracking down the yield bug. Turned out to be three little bugs. The first was a mistake in pulling the stackframes off during the actual yield call. It kept the top frame pointing to itself for restart rather than just letting it restart. The second was a missing part of while loops. If the loop knew it could yield, it didn't reset the execution pointer when it was time to restart the loop. The third was improperly handling the 'end of method' implicit return. That causes the method to run 1 extra time before signaling 'done' in some cases.

The first two have been fixed, the third hasn't yet. I'll need to add that implied return statement or some workaround that detects it was hit and change behaviors.


But the target example code has been reached, so yield is now considered functional (if yet in need of polish). Behold, a simple Fibonacci program:

 public yields<int> fib(){	local int a = 0;	local int b = 1;	local int c;	yield(a);	yield(b);	while(c < 100){		c = a + b;		yield(c);		a = b;		b = c;	}	return();}public static void main(){	foreach(int i in fib()){		print i " ";	}}	


The next test I think will involve making a functional language style take. That will involve testing yield generators with parameters, and phrase style yields. Eventually I want something like

foreach( int i in take 5 from the Fibonacci Sequence ){ ... }

to do what it means (possibly replacing 'take' with something more descriptive).
Previous Entry Tangent: Yield, part 3
Next Entry Weekend work
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement