<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-18241482.post2092370221637177302..comments</id><updated>2010-01-02T23:02:11.686-08:00</updated><title type='text'>Comments on Programming and Debugging (in my Underhøøsen): The Power of Foreach</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://the-free-meme.blogspot.com/feeds/2092370221637177302/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/2092370221637177302/comments/default'/><link rel='alternate' type='text/html' href='http://the-free-meme.blogspot.com/2009/06/power-of-foreach.html'/><author><name>The Free Meme</name><uri>http://www.blogger.com/profile/08287129746971472910</uri><email>cristi.vlasceanu@gmail.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-18241482.post-1444896950703033195</id><published>2009-11-21T21:36:48.508-08:00</published><updated>2009-11-21T21:36:48.508-08:00</updated><title type='text'>...please where can I buy a unicorn?</title><content type='html'>...please where can I buy a unicorn?</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/2092370221637177302/comments/default/1444896950703033195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/2092370221637177302/comments/default/1444896950703033195'/><link rel='alternate' type='text/html' href='http://the-free-meme.blogspot.com/2009/06/power-of-foreach.html?showComment=1258868208508#c1444896950703033195' title=''/><author><name>Anonymous</name><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://the-free-meme.blogspot.com/2009/06/power-of-foreach.html' ref='tag:blogger.com,1999:blog-18241482.post-2092370221637177302' source='http://www.blogger.com/feeds/18241482/posts/default/2092370221637177302' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-18241482.post-8377082077556458649</id><published>2009-06-25T19:12:08.262-07:00</published><updated>2009-06-25T19:12:08.262-07:00</updated><title type='text'>BCSd, this is a great observation. 

I compiled an...</title><content type='html'>BCSd, this is a great observation. &lt;br /&gt;&lt;br /&gt;I compiled and tested the code snippets before posting, and they do work for the specific examples (where I break out of the foreach loops), but you are right: the correct implementation is for opApply to return the result of the delegate call.&lt;br /&gt;&lt;br /&gt;And this just gives me some ideas for interesting test cases for my compiler back-end.&lt;br /&gt;&lt;br /&gt;Thanks!</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/2092370221637177302/comments/default/8377082077556458649'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/2092370221637177302/comments/default/8377082077556458649'/><link rel='alternate' type='text/html' href='http://the-free-meme.blogspot.com/2009/06/power-of-foreach.html?showComment=1245982328262#c8377082077556458649' title=''/><author><name>The Free Meme</name><uri>http://www.blogger.com/profile/08287129746971472910</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='05942387056293398693'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://the-free-meme.blogspot.com/2009/06/power-of-foreach.html' ref='tag:blogger.com,1999:blog-18241482.post-2092370221637177302' source='http://www.blogger.com/feeds/18241482/posts/default/2092370221637177302' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-18241482.post-1765070368359091621</id><published>2009-06-25T10:28:46.886-07:00</published><updated>2009-06-25T10:28:46.886-07:00</updated><title type='text'>That is a nice overview of D's foreach system.

Ho...</title><content type='html'>That is a nice overview of D&amp;#39;s foreach system.&lt;br /&gt;&lt;br /&gt;However your code examples have one major flaw (I&amp;#39;m sure this is true in D1 but I think it is also true in D2):&lt;br /&gt;&lt;br /&gt;The value returned by the delegate in opApply is not just a zero/non-zero value. The actual value is important. If the delegate returns a non-zero value, opApply MUST return that value or bazaar things start happening.&lt;br /&gt;&lt;br /&gt;The easy way to implement this is:&lt;br /&gt;&lt;br /&gt;if(auto ret = dg(val)) return ret;&lt;br /&gt;&lt;br /&gt;The under the hood reason for this is that if the body of the delegate has more than one exit path (say a goto, a labeled break, a return, etc.) the foreach code detects which of these to do by examining the return value of opApply.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/2092370221637177302/comments/default/1765070368359091621'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/18241482/2092370221637177302/comments/default/1765070368359091621'/><link rel='alternate' type='text/html' href='http://the-free-meme.blogspot.com/2009/06/power-of-foreach.html?showComment=1245950926886#c1765070368359091621' title=''/><author><name>BCSd</name><uri>http://www.blogger.com/profile/13116517988033017470</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://the-free-meme.blogspot.com/2009/06/power-of-foreach.html' ref='tag:blogger.com,1999:blog-18241482.post-2092370221637177302' source='http://www.blogger.com/feeds/18241482/posts/default/2092370221637177302' type='text/html'/></entry></feed>