Cw Confusion.

I've been playing around with Cw alot since the preview was released. I'm pretty sure that I'm starting to understand the concepts now. However the following problem still has me puzzled:

using System;

public class Test
{
 static int* FromTo(int a, int b)
 {
  for(int i=a; i<b; i++)
   yield return i;
 }

 static void Main()
 {
  FromTo(0,10).ToString().{Console.Write(it);};
 }
}

yields the following output:

Test+closure:496621

I would have expected:

0123456789

I've also tried this which does the same thing:

string* nums = FromTo(0,10).ToString();
nums.{Console.Write(it);};

This seems to work:

FromTo(0,10).{Console.Write(it.ToString());};

But, what I wanted to see work was the "lifting" of the ToString() method across all the ints. I'm chalking this up to alpha bits. I think whats happening is the compiled code is getting confused between the ToString() of System.Int32 and the ToString() that is part of a codegened "closure" class. On the other hand I could be totally missing something.

1 Comment

  • It's actually an old design feature that member access should be lifted *except* when it's supported by the stream itself. (If you look at page 17 of the Meijer/Schulte &quot;unifying tables, objects and documents&quot; paper you'll see this design decision. If you look at the Meijer/Schulte/Bierman version of the paper, you'll see that it silently disappeared!)



    Anyhow, to get the effect you want, try:



    FromTo(1,10).{return it.ToString();}.{Console.WriteLine(it);}



    Hopefully we'll correct this in a future build.

Comments have been disabled for this content.