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

Day of work: Entry 1

Sign in to follow this  
Telastyn

208 views

After a late awakening, I set into work on Tangent. As a warmup, I added support for the modulo operator (%). Takes two ints, returns the remainder; no big deal. Then came adding an automatic return at the end of yield blocks so the last value wasn't yielded twice. No problem.

I then figured that I better break the take implementation into two parts since there's two things to test. One being using yield methods with parameters, and the second being making phrase-y yield methods. So, the un-phrased test of take:


public static yields<int> take(int amount, IEnumerable<int> fromCollection){
local int ix = 0;
foreach( int rtn in fromCollection ){
if( !(ix < amount) ){
return();
}
yield rtn;
ix = ix + 1;
}
}

public static yields<int> allInt(){
local int i = 0;
while(true){
yield i;
i = i + 1;
}
}

public static void main(){
foreach( int x in take(5,allInt()) ){
print x;
}
}





As comes as no real surprise, it didn't work.

First problem was an error where the runtime was trying to access Param[1] when it didn't exist. Tracked that down to the take yield method. The anonymous enumerator didn't have amount or fromCollection so the name resolver found a higher level method, which was crap. Turns out the variables I was using to set the members of the anonymous enumerator weren't what I thought they were. Oops.

Second problem was an error where the runtime was looking for .amount and dying. Makes sense, it should've resolved to this.amount. Turns out that the invocation setup for the yieldy method was being dumb and treating it like a static method.

Third problem was an infinite loop. Tracked that down to the inner loop of take. It wasn't exiting the loop, even though the conditional was processed correctly. It seems I was a little incomplete in my updating loops to be yield-block aware. The foreach loop wasn't detecting the yield 'pause' correctly, so just looped again.

And then the code compiled and ran! It spit out: 02468

Doh. I am going to take a break before trying to figure what wildly convoluted stupidity I've managed to cause that sort of error.
Sign in to follow this  


3 Comments


Recommended Comments

Erm, sounds like the yields are (possibly) getting combined somehow. o_O Also, why the deuce are you using two seperate values, rtn and ix? Wouldn't it be better to do away with ix and use rtn for the evaluation?

[Edit]
Anyway problems are being caused by there essentially being a foreach within another foreach?

Share this comment


Link to comment
Well, the conceptual implementation of take is that it returns the first N elements of a list. That the list in the example happens to be the same as the counter is coincidence.

And yes, there's likely some sort of problem due to the yield nesting; likely something where the inner method isn't being restarted like it should. Time to debug...

Share this comment


Link to comment
Quote:
Original post by Telastyn
Well, the conceptual implementation of take is that it returns the first N elements of a list. That the list in the example happens to be the same as the counter is coincidence.

Oh dur. I should pay attention more.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!