<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Iterator Blocks, Part Two: Why no ref or out parameters?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/07/13/iterator-blocks-part-two-why-no-ref-or-out-parameters.aspx</link><description>A long and detailed discussion of how exactly we implement iterator blocks would take me quite a while, and would duplicate work that has been done well by others already. I encourage you to start with Raymond’s series, which is a pretty gentle introduction</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Iterator Blocks, Part Two: Why no ref or out parameters?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/07/13/iterator-blocks-part-two-why-no-ref-or-out-parameters.aspx#10027077</link><pubDate>Fri, 18 Jun 2010 14:45:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10027077</guid><dc:creator>Rich</dc:creator><description>&lt;p&gt;I&amp;#39;ll tell you why we need it, recursive inheritance.&lt;/p&gt;
&lt;p&gt;Consider an XML document where element may (optionall) inherit from their parents and you need to parse this with a streaming approach (not DOM)....you&amp;#39;ll need to keep track of the most specific values that might apply to a child as you recurse through the document each time you find something more specific you overwrite what you previously found until you find the leaf you&amp;#39;re looking for and it&amp;#39;ll have the most specific inherited properties nicely ready to yield return...that&amp;#39;s why!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10027077" width="1" height="1"&gt;</description></item><item><title>re: Iterator Blocks, Part Two: Why no ref or out parameters?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/07/13/iterator-blocks-part-two-why-no-ref-or-out-parameters.aspx#9843017</link><pubDate>Tue, 21 Jul 2009 10:52:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9843017</guid><dc:creator>Jack</dc:creator><description>&lt;p&gt;Great, I also read Jon’s article, learn a lot from it&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9843017" width="1" height="1"&gt;</description></item><item><title>re: Iterator Blocks, Part Two: Why no ref or out parameters?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/07/13/iterator-blocks-part-two-why-no-ref-or-out-parameters.aspx#9835892</link><pubDate>Thu, 16 Jul 2009 21:00:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9835892</guid><dc:creator>Alexey Romanov</dc:creator><description>&lt;p&gt;If I may ask, was anything like generalized interfaces from the paper &amp;quot;JavaGI: Generalized Interfaces for Java&amp;quot; (Stefan Wehr, Ralf L&amp;#228;mmel, Peter Thiemann) ever on the list? &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9835892" width="1" height="1"&gt;</description></item><item><title>re: Iterator Blocks, Part Two: Why no ref or out parameters?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/07/13/iterator-blocks-part-two-why-no-ref-or-out-parameters.aspx#9834316</link><pubDate>Wed, 15 Jul 2009 17:57:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9834316</guid><dc:creator>Daniel Smith</dc:creator><description>&lt;P&gt;Out of interest, what are the current "top 5" features that haven't yet made it into the language yet?&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;Yeah, I wish I knew too. (No joke!)&lt;/P&gt;
&lt;P&gt;It is way too early to speculate on that, and we don't know ourselves. The last time I mentioned an idea that we were kicking around in the hallway, I got 50+ comments criticizing the fact that we were even considering it. I don't want to get 250+ negative comments by discussing a possible feature set for an unannounced, hypothetical product. Talking about feature sets of hypothetical future versions would be extremely irresponsible at this point in the process. We haven't even shipped C# 4.0 yet. -- Eric&lt;/P&gt;&lt;/DIV&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9834316" width="1" height="1"&gt;</description></item><item><title>re: Iterator Blocks, Part Two: Why no ref or out parameters?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/07/13/iterator-blocks-part-two-why-no-ref-or-out-parameters.aspx#9834289</link><pubDate>Wed, 15 Jul 2009 17:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9834289</guid><dc:creator>Leopold Bushkin</dc:creator><description>&lt;p&gt;Perhaps you already aluded to this, but iterator blocks make it possible to implement continuations in C# programs without any additional language features. In, fact, I've done so on several occasions. The syntax isn't always the clearest, but it works quite well.&lt;/p&gt;
&lt;p&gt;The basic pattern I've used is to create an iterator block that returns a Func&amp;lt;&amp;gt; of some sort that encapsulates the individual sequences of computations that represent the continuation. Each is returned by the iterator block and then invoked by the caller. It's by the way, not dissimilar from the CCR implementation in the MS robotics library.&lt;/p&gt;
&lt;p&gt;Here's a simple example of a factorial using CPS programming:&lt;/p&gt;
&lt;p&gt;public class Continuations&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public static void Main(string[] args)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var i = 0;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var val = 0;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// output each step in the Factorial function until you compute the final value&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;foreach( var facStep in FactorialCPS.Factorial( 8 ) )&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine( &amp;quot;Step {0} = {1}&amp;quot;, ++i, val = facStep() );&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine( &amp;quot;Factorial of 8 is {0}&amp;quot;, val );&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;public static class FactorialCPS&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public static IEnumerable&amp;lt;Func&amp;lt;int&amp;gt;&amp;gt; Factorial( int n )&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int q = 1, f = 1;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;while( q &amp;lt;= n )&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;yield return () =&amp;gt; f *= q++; &amp;nbsp;// Note: uses closures to capture state&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9834289" width="1" height="1"&gt;</description></item><item><title>re: Iterator Blocks, Part Two: Why no ref or out parameters?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/07/13/iterator-blocks-part-two-why-no-ref-or-out-parameters.aspx#9833295</link><pubDate>Tue, 14 Jul 2009 19:27:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9833295</guid><dc:creator>aaron</dc:creator><description>&lt;P&gt;&amp;gt; The designers of the CLR were faced with three choices&lt;/P&gt;
&lt;P&gt;I think you missed a couple of other choices that are well established options in this area, which appears closely related to the "downward funargs problem". 4) detect when the lifetime of the object being referenced has expired, and prevent accesses after that point. 5) lift the object to the heap when its current storage location is expiring.&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;Good point. I normally end lists of options with "do something I haven't thought of". I'll update the text. -- Eric&lt;/P&gt;&lt;/DIV&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9833295" width="1" height="1"&gt;</description></item><item><title>re: Iterator Blocks, Part Two: Why no ref or out parameters?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/07/13/iterator-blocks-part-two-why-no-ref-or-out-parameters.aspx#9832912</link><pubDate>Tue, 14 Jul 2009 11:41:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9832912</guid><dc:creator>ShuggyCoUk</dc:creator><description>&lt;p&gt;&amp;quot;if it ever makes it into the top five, we'll probably implement it. -- Eric&amp;quot;&lt;/p&gt;
&lt;p&gt;This is one of the reasons that, despite the very long incubation period associated with f# I'm glad it had that time to be used in the real world with everyone using it knowing it was, in effect, beta and subject to change as feedback allowed it to grow/change.&lt;/p&gt;
&lt;p&gt;Do you think things would have been different with c# had it had a more extensive beta period(*)?&lt;/p&gt;
&lt;p&gt;(*) obviously this is hypothetical, I don't believe it would be as successful had it had anything like as long a beta as f#.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9832912" width="1" height="1"&gt;</description></item><item><title>re: Iterator Blocks, Part Two: Why no ref or out parameters?</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/07/13/iterator-blocks-part-two-why-no-ref-or-out-parameters.aspx#9832355</link><pubDate>Tue, 14 Jul 2009 00:43:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9832355</guid><dc:creator>Alexey Romanov</dc:creator><description>&lt;P&gt;What I really want to know is, why no "yield foreach"? The paper on design on CLR iterators explains its advantages and how to implement it. What are downsides to implementing it?&lt;/P&gt;
&lt;DIV class=yellowbox&gt;
&lt;P&gt;The downside is that we'd have to cut something better. We have a list of a couple&amp;nbsp;&lt;EM&gt;hundred&lt;/EM&gt;&amp;nbsp;possible new language features for any given version of C#. We have the design, implementation, testing, documentation and management resources available to actually implement maybe four or five&amp;nbsp;of them in any one version. "yield foreach" is an awesome feature that I would love to do; it is certainly in the top fifty, but has never made it into the top ten. If it ever makes it into&amp;nbsp;the top five,&amp;nbsp;we'll probably&amp;nbsp;implement it.&amp;nbsp;-- Eric&lt;/P&gt;&lt;/DIV&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9832355" width="1" height="1"&gt;</description></item></channel></rss>