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.
[Edit]
Anyway problems are being caused by there essentially being a foreach within another foreach?