<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Spark's Pensieve - Languages</title>
    <link>http://www.thinkingms.com/pensieve/</link>
    <description>Roshan James</description>
    <language>en-us</language>
    <copyright>Roshan James</copyright>
    <lastBuildDate>Sun, 06 Apr 2008 14:55:25 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>roshan.james@gmail.com</managingEditor>
    <webMaster>roshan.james@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=79ad01a3-4c10-424e-a044-49b16f9277bf</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,79ad01a3-4c10-424e-a044-49b16f9277bf.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,79ad01a3-4c10-424e-a044-49b16f9277bf.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=79ad01a3-4c10-424e-a044-49b16f9277bf</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was speaking with a friend the other day and we were talking about the interaction
of effects and how to explain them. 
</p>
        <p>
One informal way to explain some additions to languages are that they are scale down
localized structured versions of features that were largely available for the whole
program. Let me explain: Did you start programming with an imperative language with
global variables? (There is one called C that affected the minds of many people.)
When you switch to an object oriented language, someone might have explained to you
that there is no longer any need for real global variables. You may make these wannabe
globals members of a class. You can turn methods that need the globals into members
of that class as well. So they are global as far as the methods in question go, but
they are not truly global. 
</p>
        <p>
In much the same way, we can explain yield. Programming languages have always had
input and output operators - scanf-printf, gets-puts etc. However these operators
are global with respect to your program. When you execute a printf, it is the output
of the whole program, not of any one part of it. Yield on the other hand can be thought
of as a localized input output operator. You can yield values from one part of the
program to another part of the program. You get input from one part of the program.
A method that yields is a packaged up opaque entity, a little sub-program, that communicates
using yield with its consuming-context, the rest of the program.
</p>
        <p>
We can explain exceptions in this way as well. In the absence of exceptions when there
was a fault, the whole program would come down. It would core dump, modulo global
error handlers. The whole machine does not come down, just the program that faults
does. The environment that hosts the program may realize that there is a fault and
do something about it. Its much the same with exceptions, but with the difference
that only a part of the program "core dumps". Its a localized failure of the program
that the environment (the rest of the program) can handle (or not handle, thereby
making it a global failure).
</p>
        <p>
So can you play this game or any other global program features, turning them into
powerful localized structured operators?
</p>
        <img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=79ad01a3-4c10-424e-a044-49b16f9277bf" />
      </body>
      <title>Yield and Exceptions: The &amp;quot;Structured Localized&amp;quot; perspective</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,79ad01a3-4c10-424e-a044-49b16f9277bf.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2008/04/06/YieldAndExceptionsTheQuotStructuredLocalizedquotPerspective.aspx</link>
      <pubDate>Sun, 06 Apr 2008 14:55:25 GMT</pubDate>
      <description>&lt;p&gt;
I was speaking with a friend the other day and we were talking about the interaction
of effects and how to explain them. 
&lt;/p&gt;
&lt;p&gt;
One informal way to explain some additions to languages are that they are scale down
localized structured versions of features that were largely available for the whole
program. Let me explain: Did you start programming with an imperative language with
global variables? (There is one called C that affected the minds of many people.)
When you switch to an object oriented language, someone might have explained to you
that there is no longer any need for real global variables. You may make these wannabe
globals members of a class. You can turn methods that need the globals into members
of that class as well. So they are global as far as the methods in question go, but
they are not truly global. 
&lt;/p&gt;
&lt;p&gt;
In much the same way, we can explain yield. Programming languages have always had
input and output operators - scanf-printf, gets-puts etc. However these operators
are global with respect to your program. When you execute a printf, it is the output
of the whole program, not of any one part of it. Yield on the other hand can be thought
of as a localized input output operator. You can yield values from one part of the
program to another part of the program. You get input from one part of the program.
A method that yields is a packaged up opaque entity, a little sub-program, that communicates
using yield with its consuming-context, the rest of the program.
&lt;/p&gt;
&lt;p&gt;
We can explain exceptions in this way as well. In the absence of exceptions when there
was a fault, the whole program would come down. It would core dump, modulo global
error handlers. The whole machine does not come down, just the program that faults
does. The environment that hosts the program may realize that there is a fault and
do something about it. Its much the same with exceptions, but with the difference
that only a part of the program "core dumps". Its a localized failure of the program
that the environment (the rest of the program) can handle (or not handle, thereby
making it a global failure).
&lt;/p&gt;
&lt;p&gt;
So can you play this game or any other global program features, turning them into
powerful localized structured operators?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=79ad01a3-4c10-424e-a044-49b16f9277bf" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,79ad01a3-4c10-424e-a044-49b16f9277bf.aspx</comments>
      <category>Computer Science</category>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=7be176a6-1a25-4ed7-bafa-74f8365c5f97</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,7be176a6-1a25-4ed7-bafa-74f8365c5f97.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,7be176a6-1a25-4ed7-bafa-74f8365c5f97.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=7be176a6-1a25-4ed7-bafa-74f8365c5f97</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <em>An odd idea from a few days ago: </em>
        </p>
        <p>
I watched this video a while back, this is Richard Feynman giving a lecture about
discovering laws in physics - 
</p>
        <div class="wlWriterSmartContent" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:ee766944-74fd-4a77-b88c-43f0667d2406" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
          <div id="5b226bfa-f1dd-4df2-a451-ad25fbec2daf" style="margin: 0px; padding: 0px; display: inline;">
            <div>
              <a href="http://www.youtube.com/watch?v=d1ZtRN-iGdQ&amp;rel=1" target="_new">
                <img src="http://www.thinkingms.com/pensieve/content/binary/FormalSystemsConsistencyandPhilosophyofS_B3/videof1948086ffd1.jpg" galleryimg="no" onload="var downlevelDiv = document.getElementById('5b226bfa-f1dd-4df2-a451-ad25fbec2daf'); downlevelDiv.innerHTML = &quot;&lt;div&gt;&lt;object width=\&quot;425\&quot; height=\&quot;350\&quot;&gt;&lt;param name=\&quot;movie\&quot; value=\&quot;http://www.youtube.com/v/d1ZtRN-iGdQ&amp;rel=1\&quot;&gt;&lt;\/param&gt;&lt;param name=\&quot;wmode\&quot; value=\&quot;transparent\&quot;&gt;&lt;\/param&gt;&lt;embed src=\&quot;http://www.youtube.com/v/d1ZtRN-iGdQ&amp;rel=1\&quot; type=\&quot;application/x-shockwave-flash\&quot; wmode=\&quot;transparent\&quot; width=\&quot;425\&quot; height=\&quot;350\&quot;&gt;&lt;\/embed&gt;&lt;\/object&gt;&lt;\/div&gt;&quot;;" alt="" />
              </a>
            </div>
          </div>
        </div>
        <p>
He is talking about laws in physics. (the underlying <em>Philosophy of Science</em> that
Feynman describes here is due to <a href="http://en.wikipedia.org/wiki/Karl_Popper">Karl
Popper</a>)
</p>
        <p>
What Feynman is describing seems fundamentally different from what we do in the formal
sciences like math/logic/cs. In the later we usually choose an axiom set that we believe
to be right, based on our aesthetics, and then go on to prove other things that are
right wrt our axioms.  Only things that are provable are taken to right and things
that are right are irrefutably so. The system is <em>inconsistent</em> if we deduce <em>False</em> from
the rules that we have. Inconsistent systems are not interesting. All formal methods
work like this, in spirit - they keep track of what is right.
</p>
        <p>
In what Feynman is describing, they don’t have a formal notion of right. They
have a notion of what is wrong and as long as something cannot be constructively (by
experiment) shown to be wrong, they can temporarily accept it to be not-wrong. If
you look at this as a formal system, this is one where “what is not wrong yet”
is known instead of what is right. Something is not wrong because 1) We don’t
know a proof by which we can construct F from it or 2) Given our current inference
rules there is no proof for it. But, we may add a new inference rule to the system
in the future which may invalidate the belief that something is not wrong. It’s
a feels like the opposite of what we do with logics. 
</p>
        <p>
Imagine a formal system or a model of computation based on notion like this. We are,
in a fundamental sense, giving up the notion of consistency and completeness when
we do this. I wonder if there exists a computational model that corresponds to such
a “co-logic” of the sort they use in the *real* sciences. Such a system,
in spirit, might be able to deal with partially correct data, incorrect assumptions
etc. in a natural way. Absolutely correct data (or properties about the data) would
be the exception. 
</p>
        <p>
          <em>(I wonder what this implies for the incompleteness theorem and such. I have been
told that the "co-logic" I refer to here is actually co-induction. I see
some similarities there, but I am not sure if its exactly that. )</em>
        </p>
        <p>
          <a title="A Tutorial on (Co)Algebras and (Co)Induction - Jacobs, Rutten" href="http://citeseer.ist.psu.edu/jacobs97tutorial.html">A
Tutorial on (Co)Algebras and (Co)Induction - Jacobs, Rutten</a>
        </p>
        <p>
          <a title="A Tutorial on Co-induction and Functional Programming" href="http://research.microsoft.com/users/adg/publications/fp94.ps.gz">A
Tutorial on Co-induction and Functional Programming</a>
        </p>
        <img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=7be176a6-1a25-4ed7-bafa-74f8365c5f97" />
      </body>
      <title>Formal Systems, Consistency and Philosophy of Science</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,7be176a6-1a25-4ed7-bafa-74f8365c5f97.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2007/11/28/FormalSystemsConsistencyAndPhilosophyOfScience.aspx</link>
      <pubDate>Wed, 28 Nov 2007 05:03:05 GMT</pubDate>
      <description>&lt;p&gt;
&lt;em&gt;An odd idea from a few days ago: &lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
I watched this video a while back, this is Richard Feynman giving a lecture about
discovering laws in physics - 
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:ee766944-74fd-4a77-b88c-43f0667d2406" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;
&lt;div id="5b226bfa-f1dd-4df2-a451-ad25fbec2daf" style="margin: 0px; padding: 0px; display: inline;"&gt;
&lt;div&gt;&lt;a href="http://www.youtube.com/watch?v=d1ZtRN-iGdQ&amp;amp;rel=1" target="_new"&gt;&lt;img src="http://www.thinkingms.com/pensieve/content/binary/FormalSystemsConsistencyandPhilosophyofS_B3/videof1948086ffd1.jpg" galleryimg="no" onload="var downlevelDiv = document.getElementById('5b226bfa-f1dd-4df2-a451-ad25fbec2daf'); downlevelDiv.innerHTML = &amp;quot;&amp;lt;div&amp;gt;&amp;lt;object width=\&amp;quot;425\&amp;quot; height=\&amp;quot;350\&amp;quot;&amp;gt;&amp;lt;param name=\&amp;quot;movie\&amp;quot; value=\&amp;quot;http://www.youtube.com/v/d1ZtRN-iGdQ&amp;amp;rel=1\&amp;quot;&amp;gt;&amp;lt;\/param&amp;gt;&amp;lt;param name=\&amp;quot;wmode\&amp;quot; value=\&amp;quot;transparent\&amp;quot;&amp;gt;&amp;lt;\/param&amp;gt;&amp;lt;embed src=\&amp;quot;http://www.youtube.com/v/d1ZtRN-iGdQ&amp;amp;rel=1\&amp;quot; type=\&amp;quot;application/x-shockwave-flash\&amp;quot; wmode=\&amp;quot;transparent\&amp;quot; width=\&amp;quot;425\&amp;quot; height=\&amp;quot;350\&amp;quot;&amp;gt;&amp;lt;\/embed&amp;gt;&amp;lt;\/object&amp;gt;&amp;lt;\/div&amp;gt;&amp;quot;;" alt=""&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
He is talking about laws in physics. (the underlying &lt;em&gt;Philosophy of Science&lt;/em&gt; that
Feynman describes here is due to &lt;a href="http://en.wikipedia.org/wiki/Karl_Popper"&gt;Karl
Popper&lt;/a&gt;)
&lt;/p&gt;
&lt;p&gt;
What Feynman is describing seems fundamentally different from what we do in the formal
sciences like math/logic/cs. In the later we usually choose an axiom set that we believe
to be right, based on our aesthetics, and then go on to prove other things that are
right wrt our axioms.&amp;#160; Only things that are provable are taken to right and things
that are right are irrefutably so. The system is &lt;em&gt;inconsistent&lt;/em&gt; if we deduce &lt;em&gt;False&lt;/em&gt; from
the rules that we have. Inconsistent systems are not interesting. All formal methods
work like this, in spirit - they keep track of what is right.
&lt;/p&gt;
&lt;p&gt;
In what Feynman is describing, they don&amp;#8217;t have a formal notion of right. They
have a notion of what is wrong and as long as something cannot be constructively (by
experiment) shown to be wrong, they can temporarily accept it to be not-wrong. If
you look at this as a formal system, this is one where &amp;#8220;what is not wrong yet&amp;#8221;
is known instead of what is right. Something is not wrong because 1) We don&amp;#8217;t
know a proof by which we can construct F from it or 2) Given our current inference
rules there is no proof for it. But, we may add a new inference rule to the system
in the future which may invalidate the belief that something is not wrong. It&amp;#8217;s
a feels like the opposite of what we do with logics. 
&lt;/p&gt;
&lt;p&gt;
Imagine a formal system or a model of computation based on notion like this. We are,
in a fundamental sense, giving up the notion of consistency and completeness when
we do this. I wonder if there exists a computational model that corresponds to such
a &amp;#8220;co-logic&amp;#8221; of the sort they use in the *real* sciences. Such a system,
in spirit, might be able to deal with partially correct data, incorrect assumptions
etc. in a natural way. Absolutely correct data (or properties about the data) would
be the exception. 
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;(I wonder what this implies for the incompleteness theorem and such. I have been
told that the &amp;quot;co-logic&amp;quot; I refer to here is actually co-induction. I see
some similarities there, but I am not sure if its exactly that. )&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a title="A Tutorial on (Co)Algebras and (Co)Induction - Jacobs, Rutten" href="http://citeseer.ist.psu.edu/jacobs97tutorial.html"&gt;A
Tutorial on (Co)Algebras and (Co)Induction - Jacobs, Rutten&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a title="A Tutorial on Co-induction and Functional Programming" href="http://research.microsoft.com/users/adg/publications/fp94.ps.gz"&gt;A
Tutorial on Co-induction and Functional Programming&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=7be176a6-1a25-4ed7-bafa-74f8365c5f97" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,7be176a6-1a25-4ed7-bafa-74f8365c5f97.aspx</comments>
      <category>Computer Science</category>
      <category>Languages</category>
      <category>Mathematics</category>
      <category>Mish Mash</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=295d5fe8-9647-44f1-87ed-44e961e7d5b3</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,295d5fe8-9647-44f1-87ed-44e961e7d5b3.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,295d5fe8-9647-44f1-87ed-44e961e7d5b3.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=295d5fe8-9647-44f1-87ed-44e961e7d5b3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Being at Indiana University, which is an old time Scheme hub, every now and then I
am exposed to some of the turmoil in Scheme community over the new Scheme standard,
R6RS. Essentially the community is having a hard time agreeing on what should be in
the new standard. There are some very smart, very accomplished, very opinionated people
who belong to this community and the language spec <a href="http://lists.r6rs.org/pipermail/r6rs-discuss/2007-October/003351.html">is
a bit of a battle ground</a>, from what I hear. (As are all language specs... some
battles, I suspect, lack the intellectual quality of this one)
</p>
        <p>
I am not very much of a Schemer myself, I sometimes indulge the language on a need
basis. I hear from some my more intensely-Scheme-happy friends about some of the latest
news at Scheme-spec land. One of the names that was mentioned in recent times is that
of Will Clinger. Apparently, Will Clinger set into motion some of the discussion that
formed the origins of the new standard, called R6RS (that is short for Revision-6
of the Report on Scheme - or something approximately like that). Over the years the
formalization of R6RS has had its ups and downs. Of the many differences of opinion
on the standard, some resulted in the formation of a group that decided to create
an alternate standard. This group is called SchemePunks, apparently headed by Will
Clinger himself (<a href="http://lists.r6rs.org/pipermail/r6rs-discuss/2007-June/002475.html">*</a>).
While this is mostly hearsay, it seemed amusing none the less. I also, sort of, like
Scheme - so I listen in when one of these conversations come up. 
</p>
        <p>
Today I was searching for something and I came across the SchemePunks webpage/wiki.
I didn't realize they had a webpage. Better yet no one told me that it written in
excellent Hitchiker style! I read this and burst out laughing - what a way to motivate
a language standard! I don't know any of the design decisions they have made, but
the introduction here is sheer genius. Despite not being a Schemer, I am almost tempted
to join in. :)
</p>
        <p>
          <a href="http://scheme-punks.cyber-rush.org/wiki/index.php?title=Main_Page">From the
SchemePunks webpage:</a>
        </p>
        <blockquote>
          <p>
            <em>On 29 August 2007, the </em>
            <a href="http://www.r6rs.org:Revised/">
              <em>Revised
Revised Revised Revised Revised Revised Report on Scheme</em>
            </a>
            <em> was ratified
by the Steering Committee. This has made a lot of people quite angry and has been
widely regarded as a bad move. </em>
          </p>
          <p>
            <em>Many programmers believe that it was created by some sort of community process,
though the Jatravartid people of Viltvodle VI believe that the entire Standard was
in fact sneezed out of the nose of a being called the Great Green Arkleseizure. This
theory is not widely accepted outside Viltvodle VI, and so, standards being the puzzling
documents that they are, other standards are being designed. And this wiki, which
is called SchemePunks, is definitely not part of the Scheme Underground, even if it
is, which it isn't. </em>
          </p>
          <p>
            <em>Which is very odd, because without that fairly simple piece of knowledge, nothing
that is written on here could possibly make the slightest bit of sense. We hope to
develop an alternative specification for the Family of Programming Languages known
as Scheme. Watch this space</em>. 
</p>
        </blockquote>
        <p>
Being somewhat bowled over, I had to look for the man - William Clinger, Professor
of Computer Science, Northeastern U. 
<br /><a title="http://www.ccs.neu.edu/home/will/Personal/western1.jpg" href="http://www.ccs.neu.edu/home/will/Personal/western1.jpg">http://www.ccs.neu.edu/home/will/Personal/western1.jpg</a></p>
        <p>
:) 
</p>
        <p>
I wish more languages where designed in H2G2 spirit. Aah!
</p>
        <p>
From his webpage: 
<br /><a title="http://www.ccs.neu.edu/home/will/R6RS/essay.txt" href="http://www.ccs.neu.edu/home/will/R6RS/essay.txt">http://www.ccs.neu.edu/home/will/R6RS/essay.txt</a></p>
        <blockquote>
          <p>
More than twenty years have passed since I wrote this [1]: 
</p>
        </blockquote>
        <blockquote>
          <p>
            <em>Programming languages should be designed not by piling feature on top of feature,
but by removing the weaknesses and restrictions that make additional features appear
necessary. Scheme demonstrates that a very small number of rules for forming expressions,
with no restrictions on how they are composed, suffice to form a practical and efficient
programming language that is flexible enough to support most of the major programming
paradigms in use today.</em>
          </p>
        </blockquote>
        <p>
I have to say, I am compelled to agree, though I wonder how of it applies to the Scheme
of today. The essay is worth a read, even if you are not a Schemer. You can skip over
the Scheme specific parts and just look at the language design philosophy. 
</p>
        <img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=295d5fe8-9647-44f1-87ed-44e961e7d5b3" />
      </body>
      <title>SchemePunks. Don't Panic!</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,295d5fe8-9647-44f1-87ed-44e961e7d5b3.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2007/11/19/SchemePunksDontPanic.aspx</link>
      <pubDate>Mon, 19 Nov 2007 04:11:35 GMT</pubDate>
      <description>&lt;p&gt;
Being at Indiana University, which is an old time Scheme hub, every now and then I
am exposed to some of the turmoil in Scheme community over the new Scheme standard,
R6RS. Essentially the community is having a hard time agreeing on what should be in
the new standard. There are some very smart, very accomplished, very opinionated people
who belong to this community and the language spec &lt;a href="http://lists.r6rs.org/pipermail/r6rs-discuss/2007-October/003351.html"&gt;is
a bit of a battle ground&lt;/a&gt;, from what I hear. (As are all language specs... some
battles, I suspect, lack the intellectual quality of this one)
&lt;/p&gt;
&lt;p&gt;
I am not very much of a Schemer myself, I sometimes indulge the language on a need
basis. I hear from some my more intensely-Scheme-happy friends about some of the latest
news at Scheme-spec land. One of the names that was mentioned in recent times is that
of Will Clinger. Apparently, Will Clinger set into motion some of the discussion that
formed the origins of the new standard, called R6RS (that is short for Revision-6
of the Report on Scheme - or something approximately like that). Over the years the
formalization of R6RS has had its ups and downs. Of the many differences of opinion
on the standard, some resulted in the formation of a group that decided to create
an alternate standard. This group is called SchemePunks, apparently headed by Will
Clinger himself (&lt;a href="http://lists.r6rs.org/pipermail/r6rs-discuss/2007-June/002475.html"&gt;*&lt;/a&gt;).
While this is mostly hearsay, it seemed amusing none the less. I also, sort of, like
Scheme - so I listen in when one of these conversations come up. 
&lt;/p&gt;
&lt;p&gt;
Today I was searching for something and I came across the SchemePunks webpage/wiki.
I didn't realize they had a webpage. Better yet no one told me that it written in
excellent Hitchiker style! I read this and burst out laughing - what a way to motivate
a language standard! I don't know any of the design decisions they have made, but
the introduction here is sheer genius. Despite not being a Schemer, I am almost tempted
to join in. :)
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://scheme-punks.cyber-rush.org/wiki/index.php?title=Main_Page"&gt;From the
SchemePunks webpage:&lt;/a&gt;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;em&gt;On 29 August 2007, the &lt;/em&gt;&lt;a href="http://www.r6rs.org:Revised/"&gt;&lt;em&gt;Revised
Revised Revised Revised Revised Revised Report on Scheme&lt;/em&gt;&lt;/a&gt;&lt;em&gt; was ratified
by the Steering Committee. This has made a lot of people quite angry and has been
widely regarded as a bad move. &lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;Many programmers believe that it was created by some sort of community process,
though the Jatravartid people of Viltvodle VI believe that the entire Standard was
in fact sneezed out of the nose of a being called the Great Green Arkleseizure. This
theory is not widely accepted outside Viltvodle VI, and so, standards being the puzzling
documents that they are, other standards are being designed. And this wiki, which
is called SchemePunks, is definitely not part of the Scheme Underground, even if it
is, which it isn't. &lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;Which is very odd, because without that fairly simple piece of knowledge, nothing
that is written on here could possibly make the slightest bit of sense. We hope to
develop an alternative specification for the Family of Programming Languages known
as Scheme. Watch this space&lt;/em&gt;. 
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Being somewhat bowled over, I had to look for the man - William Clinger, Professor
of Computer Science, Northeastern U. 
&lt;br /&gt;
&lt;a title="http://www.ccs.neu.edu/home/will/Personal/western1.jpg" href="http://www.ccs.neu.edu/home/will/Personal/western1.jpg"&gt;http://www.ccs.neu.edu/home/will/Personal/western1.jpg&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
:) 
&lt;/p&gt;
&lt;p&gt;
I wish more languages where designed in H2G2 spirit. Aah!
&lt;/p&gt;
&lt;p&gt;
From his webpage: 
&lt;br /&gt;
&lt;a title="http://www.ccs.neu.edu/home/will/R6RS/essay.txt" href="http://www.ccs.neu.edu/home/will/R6RS/essay.txt"&gt;http://www.ccs.neu.edu/home/will/R6RS/essay.txt&lt;/a&gt;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
More than twenty years have passed since I wrote this [1]: 
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&lt;em&gt;Programming languages should be designed not by piling feature on top of feature,
but by removing the weaknesses and restrictions that make additional features appear
necessary. Scheme demonstrates that a very small number of rules for forming expressions,
with no restrictions on how they are composed, suffice to form a practical and efficient
programming language that is flexible enough to support most of the major programming
paradigms in use today.&lt;/em&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I have to say, I am compelled to agree, though I wonder how of it applies to the Scheme
of today. The essay is worth a read, even if you are not a Schemer. You can skip over
the Scheme specific parts and just look at the language design philosophy. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=295d5fe8-9647-44f1-87ed-44e961e7d5b3" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,295d5fe8-9647-44f1-87ed-44e961e7d5b3.aspx</comments>
      <category>Computer Science</category>
      <category>Languages</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=b3cb0721-d219-4add-b7dc-ce92a89010fb</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,b3cb0721-d219-4add-b7dc-ce92a89010fb.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,b3cb0721-d219-4add-b7dc-ce92a89010fb.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=b3cb0721-d219-4add-b7dc-ce92a89010fb</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I get irritated because too many people in the "computing" business don't understand
the word "lambda". Its just irritating because at the heart of it, its just a simple
fundamental idea, like the notion of natural numbers or counting. So just spend a
few minutes, understand what it means and stay educated. In a few years (if not already),
almost every language is going to expose something like a lambda to its programmers.
So <em>just pick up the idea ok</em>?
</p>
        <p>
This is a working description, it wont make you an expert on the Lambda Calculus.
It might give you some intuitions about it though. Lets get started. 
</p>
        <p>
So assuming you are familiar with a C-like language, how do you write a function that
takes an integer and returns it? 
</p>
        <p>
          <em>int foo(int x) {<br />
    return x;<br />
}</em>
        </p>
        <p>
Now lets look at what this is saying, it says there is a function called foo, it takes
an int which it names x and it returns an int. the body of the function has a single
statement called return x. Great! Now, this function is a very famous one and is called
the identity function (usually goes by the nick-name <em>id</em>). Also when we talk
about functional programming we dont really care very much for the C-style types.
So let's rename the function and drop the types. 
</p>
        <p>
          <em>id(x) {<br />
      return x;<br />
}</em>
        </p>
        <p>
Don't worry too much about the types. Typed functional languages usually have a different
notion of types from the C like languages. The types will come back, but in a bigger
and better form. We however wont discuss any type theory in this article. 
</p>
        <p>
So now, what it is saying? It says here is a function called id, it takes some value
that it calls x and it returns x. Ok, now lets take a look at this closely. In the
syntax that we have here, the name of the function is part of the syntax. We would
like to say - here is a function and then assign it the name id. So that we are able
to look at the function and its name as two different things. Lets do that by introducing
the keyword called "function". Javascript, for example, has such a keyword. 
</p>
        <p>
          <em>id = function(x) {<br />
      return x;<br />
}</em>
        </p>
        <p>
Ok. Now lets make one more simplification. Lets say that the language is a little
like Ruby or so where that last statement in a functions body is its return value.
Did you get that? That means that we no longer need the keyword <em>return</em>. We
can simply make the last statement x and by that we know that the return value from
the function will be x.
</p>
        <p>
          <em>id = function(x) {<br />
      x;<br />
}</em>
        </p>
        <p>
Great, lets rewrite this a bit:
</p>
        <p>
          <em>id = function(x) { x; }</em>
        </p>
        <p>
Now for one more simplification (really C like languages are so complex!) - lets assume
that we can write only one statement inside each function. Just one. If that's the
case it can be much like a <em>if </em>with just one statement - we don't need the
curly braces anymore. We also don't really need the semicolon. 
</p>
        <p>
          <em>id = function(x) x</em>
        </p>
        <p>
Great! Congratulations ladies an gentlemen, you are looking at a lambda. Simply rename
the keyword function and call it lambda and we are all set. 
</p>
        <p>
          <em>id = lambda(x) x</em>
        </p>
        <p>
If we drop the name assignment and look at it we have:
</p>
        <p>
          <em>lambda(x) x</em>
        </p>
        <p>
This is a function that has no name. It take one argument and return it. Various functional
languages use slightly different syntax for writing out their lambdas. The lambda
calculus, the underlying calculus of these systems, usually uses a \ instead of the
verbose name lambda. It also uses a dot to separate the arguments from the body of
the function. A little like this:
</p>
        <p>
          <em>\x.x</em>
        </p>
        <p>
The functional language Haskell uses an arrow to separate the body from the arguments. 
</p>
        <p>
          <em>\x-&gt;x</em>
        </p>
        <p>
The language(s) ML, OCaml, SML, (maybe F#) etc. use the name <em>fun</em> to stand
for lambda. 
</p>
        <p>
          <em>fun x -&gt; x</em>
        </p>
        <p>
The language Scheme uses the name lambda and lots of parenthesis. 
</p>
        <p>
          <em>(lambda (x) x)</em>
        </p>
        <p>
Ruby lets you write something very similar to a lambda like this:
</p>
        <p>
          <em>lambda {|x| x}</em>
        </p>
        <p>
Most of these languages give you some mechanism by which you can give a name to your
lambdas (otherwise most of the time you are a little hard pressed to refer to them). 
</p>
        <p>
Haskell 
</p>
        <p>
          <em>id = \x -&gt; x</em>
        </p>
        <p>
ML
</p>
        <p>
          <em>let id = fun x -&gt; x</em>
        </p>
        <p>
Scheme 
</p>
        <p>
          <em>(define id (lambda (x) x))</em>
        </p>
        <p>
There are some alternate syntaxes for writing named lambdas in most languages:
</p>
        <p>
Haskell 
</p>
        <p>
          <em>id x = x</em>
        </p>
        <p>
ML
</p>
        <p>
          <em>let id x = x</em>
        </p>
        <p>
Scheme 
</p>
        <p>
          <em>(define (id x) x)</em>
        </p>
        <p>
So what is a lambda? It is usually a name used to define a function. The function
is a value that can be assigned to a variable name. Just like any other value in your
language. 
</p>
        <p>
A lambda is an abstraction form. Normally in a program you can read the value of a
variable to which you have not assigned a value. In other words is you write <em>(x
+ 1)</em>, it does not have any meaning if x has not been assigned a value already.
One way to look at what lambda says is that it abstracts the value of the x. So <em>\x.(x+1)</em> means
- give me a value for x and then I will give you the value for x+1. The value of x
is <em>abstracted</em> in the body of the lambda. This description comes very close
to our informal notion of a function in a C like language. 
</p>
        <p>
The lambda calculus usually allows only for lambdas that take one argument. Hence
to write functions that take multiple arguments we nest lambdas. We write <em>\x.(\y.(x+y))</em> for
a function that adds two numbers. Most functional languages support multi-argument
lambdas. In Haskell this would be <em>\x y -&gt; (x+y)</em>. 
</p>
        <p>
So what's the big deal? Nothing much and quiet a lot. Nothing much because the notion
of functional abstraction is something we learn from high-school math which we port
over to programming languages. This is an old and familiar notion. 
</p>
        <p>
That said, in the functional programming community, it has long been realized (it
is a large community with varying beliefs, secret cults, traditions and practices)
that lambdas are <em>the only abstraction form required</em> for a lot of things. 
One can do away with loops and conditionals (if, switch) and assignments and numbers
and object oriented programming and pretty much everything you can think of (and some
things you cant) - they can all be encoded using lambdas. Hence lambdas form a sort
of foundational building block for a large number of programming paradigms. At the
heart of all of this is the <em>notion of a function</em> - hence the name <em>functional
programming</em>. 
</p>
        <img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=b3cb0721-d219-4add-b7dc-ce92a89010fb" />
      </body>
      <title>What is a Lambda? A simple working description</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,b3cb0721-d219-4add-b7dc-ce92a89010fb.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2007/11/03/WhatIsALambdaASimpleWorkingDescription.aspx</link>
      <pubDate>Sat, 03 Nov 2007 23:03:52 GMT</pubDate>
      <description>&lt;p&gt;
I get irritated because too many people in the "computing" business don't understand
the word "lambda". Its just irritating because at the heart of it, its just a simple
fundamental idea, like the notion of natural numbers or counting. So just spend a
few minutes, understand what it means and stay educated. In a few years (if not already),
almost every language is going to expose something like a lambda to its programmers.
So &lt;em&gt;just pick up the idea ok&lt;/em&gt;?
&lt;/p&gt;
&lt;p&gt;
This is a working description, it wont make you an expert on the Lambda Calculus.
It might give you some intuitions about it though. Lets get started. 
&lt;/p&gt;
&lt;p&gt;
So assuming you are familiar with a C-like language, how do you write a function that
takes an integer and returns it? 
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;int foo(int x) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return x;&lt;br&gt;
}&lt;/em&gt; 
&lt;p&gt;
Now lets look at what this is saying, it says there is a function called foo, it takes
an int which it names x and it returns an int. the body of the function has a single
statement called return x. Great! Now, this function is a very famous one and is called
the identity function (usually goes by the nick-name &lt;em&gt;id&lt;/em&gt;). Also when we talk
about functional programming we dont really care very much for the C-style types.
So let's rename the function and drop the types. 
&lt;p&gt;
&lt;em&gt;id(x) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x;&lt;br&gt;
}&lt;/em&gt; 
&lt;p&gt;
Don't worry too much about the types. Typed functional languages usually have a different
notion of types from the C like languages. The types will come back, but in a bigger
and better form. We however wont discuss any type theory in this article. 
&lt;p&gt;
So now, what it is saying? It says here is a function called id, it takes some value
that it calls x and it returns x. Ok, now lets take a look at this closely. In the
syntax that we have here, the name of the function is part of the syntax. We would
like to say - here is a function and then assign it the name id. So that we are able
to look at the function and its name as two different things. Lets do that by introducing
the keyword called "function". Javascript, for example, has such a keyword. 
&lt;p&gt;
&lt;em&gt;id = function(x) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return x;&lt;br&gt;
}&lt;/em&gt; 
&lt;p&gt;
Ok. Now lets make one more simplification. Lets say that the language is a little
like Ruby or so where that last statement in a functions body is its return value.
Did you get that? That means that we no longer need the keyword &lt;em&gt;return&lt;/em&gt;. We
can simply make the last statement x and by that we know that the return value from
the function will be x.
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;id = function(x) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x;&lt;br&gt;
}&lt;/em&gt; 
&lt;p&gt;
Great, lets rewrite this a bit:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;id = function(x) { x; }&lt;/em&gt; 
&lt;p&gt;
Now for one more simplification (really C like languages are so complex!) - lets assume
that we can write only one statement inside each function. Just one. If that's the
case it can be much like a &lt;em&gt;if &lt;/em&gt;with just one statement - we don't need the
curly braces anymore. We also don't really need the semicolon. 
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;id = function(x) x&lt;/em&gt; 
&lt;p&gt;
Great! Congratulations ladies an gentlemen, you are looking at a lambda. Simply rename
the keyword function and call it lambda and we are all set. 
&lt;p&gt;
&lt;em&gt;id = lambda(x) x&lt;/em&gt; 
&lt;p&gt;
If we drop the name assignment and look at it we have:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;lambda(x) x&lt;/em&gt; 
&lt;p&gt;
This is a function that has no name. It take one argument and return it. Various functional
languages use slightly different syntax for writing out their lambdas. The lambda
calculus, the underlying calculus of these systems, usually uses a \ instead of the
verbose name lambda. It also uses a dot to separate the arguments from the body of
the function. A little like this:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;\x.x&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
The functional language Haskell uses an arrow to separate the body from the arguments. 
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;\x-&amp;gt;x&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
The language(s) ML, OCaml, SML, (maybe F#) etc. use the name &lt;em&gt;fun&lt;/em&gt; to stand
for lambda. 
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;fun x -&amp;gt; x&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
The language Scheme uses the name lambda and lots of parenthesis. 
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;(lambda (x) x)&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Ruby lets you write something very similar to a lambda like this:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;lambda {|x| x}&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Most of these languages give you some mechanism by which you can give a name to your
lambdas (otherwise most of the time you are a little hard pressed to refer to them). 
&lt;/p&gt;
&lt;p&gt;
Haskell 
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;id = \x -&amp;gt; x&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
ML
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;let id = fun x -&amp;gt; x&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Scheme 
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;(define id (lambda (x) x))&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
There are some alternate syntaxes for writing named lambdas in most languages:
&lt;/p&gt;
&lt;p&gt;
Haskell 
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;id x = x&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
ML
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;let id x = x&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Scheme 
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;(define (id x) x)&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
So what is a lambda? It is usually a name used to define a function. The function
is a value that can be assigned to a variable name. Just like any other value in your
language. 
&lt;/p&gt;
&lt;p&gt;
A lambda is an abstraction form. Normally in a program you can read the value of a
variable to which you have not assigned a value. In other words is you write &lt;em&gt;(x
+ 1)&lt;/em&gt;, it does not have any meaning if x has not been assigned a value already.
One way to look at what lambda says is that it abstracts the value of the x. So &lt;em&gt;\x.(x+1)&lt;/em&gt; means
- give me a value for x and then I will give you the value for x+1. The value of x
is &lt;em&gt;abstracted&lt;/em&gt; in the body of the lambda. This description comes very close
to our informal notion of a function in a C like language. 
&lt;/p&gt;
&lt;p&gt;
The lambda calculus usually allows only for lambdas that take one argument. Hence
to write functions that take multiple arguments we nest lambdas. We write &lt;em&gt;\x.(\y.(x+y))&lt;/em&gt; for
a function that adds two numbers. Most functional languages support multi-argument
lambdas. In Haskell this would be &lt;em&gt;\x y -&amp;gt; (x+y)&lt;/em&gt;. 
&lt;/p&gt;
&lt;p&gt;
So what's the big deal? Nothing much and quiet a lot. Nothing much because the notion
of functional abstraction is something we learn from high-school math which we port
over to programming languages. This is an old and familiar notion. 
&lt;/p&gt;
&lt;p&gt;
That said, in the functional programming community, it has long been realized (it
is a large community with varying beliefs, secret cults, traditions and practices)
that lambdas are &lt;em&gt;the only abstraction form required&lt;/em&gt; for a lot of things.&amp;nbsp;
One can do away with loops and conditionals (if, switch) and assignments and numbers
and object oriented programming and pretty much everything you can think of (and some
things you cant) - they can all be encoded using lambdas. Hence lambdas form a sort
of foundational building block for a large number of programming paradigms. At the
heart of all of this is the &lt;em&gt;notion of a function&lt;/em&gt; - hence the name &lt;em&gt;functional
programming&lt;/em&gt;. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=b3cb0721-d219-4add-b7dc-ce92a89010fb" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,b3cb0721-d219-4add-b7dc-ce92a89010fb.aspx</comments>
      <category>Computer Science</category>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=e1317780-7d0a-44bf-895f-c19d634327c0</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,e1317780-7d0a-44bf-895f-c19d634327c0.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,e1317780-7d0a-44bf-895f-c19d634327c0.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=e1317780-7d0a-44bf-895f-c19d634327c0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This is a great slide deck from Benjamin Pierce, Professor Computer Science at UPenn,
that shows what the world of programming languages research is doing especially in
the context of types.
</p>
        <p>
          <a title="http://www.cis.upenn.edu/~bcpierce/papers/tng-lics2003-slides.pdf" href="http://www.cis.upenn.edu/~bcpierce/papers/tng-lics2003-slides.pdf">http://www.cis.upenn.edu/~bcpierce/papers/tng-lics2003-slides.pdf</a>
        </p>
        <p>
Also from Pierce is a really good introduction (the best I have found to date) about
polymorphic lambda calculi and actually programming in some of those languages. This
describes the hierarchy starting with the simply typed lambda calculus (F1) and describes
F2, F3, etc and Fw (F-omega). He also talks about encodings of various sorts of types
and a whole lot of neat stuff. All of that written in a very readable fashion. I spent
my weekend on this and it was time well spent. 
</p>
        <p>
          <a title="http://www.cis.upenn.edu/~bcpierce/papers/leap.pdf" href="http://www.cis.upenn.edu/~bcpierce/papers/leap.pdf">http://www.cis.upenn.edu/~bcpierce/papers/leap.pdf</a>
        </p>
        <p>
(For some reason this pdf seems to be back to front, but its just fine when printed)
</p>
        <p>
Pierce's <a href="http://www.cis.upenn.edu/~bcpierce/">webpage</a> is a gold mine
of information for the PL student, including neat things like a '<a href="http://www.cis.upenn.edu/~bcpierce/courses/670Fall04/GreatWorksInPL.html">Great
Works in Programming Languages</a>' list. He is also a <a href="http://alliance.seas.upenn.edu/~bcpierce/cgi-bin/photos/gallery.html">pretty
good photographer</a>. I did see him in person when I was at MSRC in summer of 2006.
I believe he was visiting those days. I now regret not having walked up to him and
saying hi. 
</p>
        <img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=e1317780-7d0a-44bf-895f-c19d634327c0" />
      </body>
      <title>Programming Languages and Types, Polymorphic Lambda Calculi</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,e1317780-7d0a-44bf-895f-c19d634327c0.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2007/10/29/ProgrammingLanguagesAndTypesPolymorphicLambdaCalculi.aspx</link>
      <pubDate>Mon, 29 Oct 2007 03:25:11 GMT</pubDate>
      <description>&lt;p&gt;
This is a great slide deck from Benjamin Pierce, Professor Computer Science at UPenn,
that shows what the world of programming languages research is doing especially in
the context of types.
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://www.cis.upenn.edu/~bcpierce/papers/tng-lics2003-slides.pdf" href="http://www.cis.upenn.edu/~bcpierce/papers/tng-lics2003-slides.pdf"&gt;http://www.cis.upenn.edu/~bcpierce/papers/tng-lics2003-slides.pdf&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Also from Pierce is a really good introduction (the best I have found to date) about
polymorphic lambda calculi and actually programming in some of those languages. This
describes the hierarchy starting with the simply typed lambda calculus (F1) and describes
F2, F3, etc and Fw (F-omega). He also talks about encodings of various sorts of types
and a whole lot of neat stuff. All of that written in a very readable fashion. I spent
my weekend on this and it was time well spent. 
&lt;/p&gt;
&lt;p&gt;
&lt;a title="http://www.cis.upenn.edu/~bcpierce/papers/leap.pdf" href="http://www.cis.upenn.edu/~bcpierce/papers/leap.pdf"&gt;http://www.cis.upenn.edu/~bcpierce/papers/leap.pdf&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
(For some reason this pdf seems to be back to front, but its just fine when printed)
&lt;/p&gt;
&lt;p&gt;
Pierce's &lt;a href="http://www.cis.upenn.edu/~bcpierce/"&gt;webpage&lt;/a&gt; is a gold mine
of information for the PL student, including neat things like a '&lt;a href="http://www.cis.upenn.edu/~bcpierce/courses/670Fall04/GreatWorksInPL.html"&gt;Great
Works in Programming Languages&lt;/a&gt;' list. He is also a &lt;a href="http://alliance.seas.upenn.edu/~bcpierce/cgi-bin/photos/gallery.html"&gt;pretty
good photographer&lt;/a&gt;. I did see him in person when I was at MSRC in summer of 2006.
I believe he was visiting those days. I now regret not having walked up to him and
saying hi. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=e1317780-7d0a-44bf-895f-c19d634327c0" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,e1317780-7d0a-44bf-895f-c19d634327c0.aspx</comments>
      <category>Computer Science</category>
      <category>Languages</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=51b8b6a5-9c64-4075-945f-be87253c27a5</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,51b8b6a5-9c64-4075-945f-be87253c27a5.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,51b8b6a5-9c64-4075-945f-be87253c27a5.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=51b8b6a5-9c64-4075-945f-be87253c27a5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <em>"Can you recommend any C++ books?"<br />
"I don't recommend C++."</em>
        </p>
        <p>
Afterwards I reluctantly come up with some names. I beginning to notice that I eventually
end up mentioning the <a href="http://www.amazon.com/exec/obidos/ASIN/0321334876/qid%3D1113923151/sr%3D11-1/ref%3Dsr_11_1/002-9542631-8380824">Scott
Meyers "Effective C++" books</a>. The last time I did this I started to wonder why
I say this?
</p>
        <p>
When I first read "Effective C++" I was horrified. If I derived any pleasure out of
it, it was comparable to the morbid curiosity of going to witness an execution (I
probably would not do that though, if I ever got such a chance. I don't have the stomach
for it). Back to C++ - Firstly there was no way I was going remember all of that.
Secondly I felt deeply uncomfortable. In time I realized that the whole book was written
in the style of demonstrating "effective" usages of C++, while what it truly was is
a careful documentation of the flaws of the language. Every chapter in that book talks
of a language flaw in excruciating detail and how to live with it. That book should
have been called "Defective C++".
</p>
        <p>
Then there was "More Effective C++" which essentially did more of the same. 
Here is what the language does, here is what you think it would do, here is what you'd
like it to do and you put these together and it blows up in your face. In time, my
intellectual immune system kicked in and started erasing most of my memories about
all this. 
</p>
        <p>
So why do I recommend the "Defective" and "More Defective" books? My first recommendation
would be to get out of the situation, don't deal with the language if that's possible.
If not, and you intend to get it to serve you (instead of the converse) you need to
quickly understand that most of the abstractions it provides are leaky. There are
hardly any non-leaky abstractions that C++-land provides. (Some people associate this
behavior with some notion of "freedom" - I trust evolution will take of those folk.) 
</p>
        <p>
So if your abstractions are leaky, in that they are going to have strange interactions
with each other under-the-hood, then you should quickly start developing an understanding
of what happens under the abstractions you are given. Your effectiveness as a developer
becomes proportional to your understanding of what happens under the surface. Hence
the "defective" C++ books are a useful read. 
</p>
        <img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=51b8b6a5-9c64-4075-945f-be87253c27a5" />
      </body>
      <title>Recommend C++?</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,51b8b6a5-9c64-4075-945f-be87253c27a5.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2007/10/19/RecommendC.aspx</link>
      <pubDate>Fri, 19 Oct 2007 17:05:29 GMT</pubDate>
      <description>&lt;p&gt;
&lt;em&gt;"Can you recommend any C++ books?"&lt;br&gt;
"I don't recommend C++."&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Afterwards I reluctantly come up with some names. I beginning to notice that I eventually
end up mentioning the &lt;a href="http://www.amazon.com/exec/obidos/ASIN/0321334876/qid%3D1113923151/sr%3D11-1/ref%3Dsr_11_1/002-9542631-8380824"&gt;Scott
Meyers "Effective C++" books&lt;/a&gt;. The last time I did this I started to wonder why
I say this?
&lt;/p&gt;
&lt;p&gt;
When I first read "Effective C++" I was horrified. If I derived any pleasure out of
it, it was comparable to the morbid curiosity of going to witness an execution (I
probably would not do that though, if I ever got such a chance. I don't have the stomach
for it). Back to C++ - Firstly there was no way I was going remember all of that.
Secondly I felt deeply uncomfortable. In time I realized that the whole book was written
in the style of demonstrating "effective" usages of C++, while what it truly was is
a careful documentation of the flaws of the language. Every chapter in that book talks
of a language flaw in excruciating detail and how to live with it. That book should
have been called "Defective C++".
&lt;/p&gt;
&lt;p&gt;
Then there was "More Effective C++" which essentially did more of the same.&amp;nbsp;
Here is what the language does, here is what you think it would do, here is what you'd
like it to do and you put these together and it blows up in your face. In time, my
intellectual immune system kicked in and started erasing most of my memories about
all this. 
&lt;/p&gt;
&lt;p&gt;
So why do I recommend the "Defective" and "More Defective" books? My first recommendation
would be to get out of the situation, don't deal with the language if that's possible.
If not, and you intend to get it to serve you (instead of the converse) you need to
quickly understand that most of the abstractions it provides are leaky. There are
hardly any non-leaky abstractions that C++-land provides. (Some people associate this
behavior with some notion of "freedom" - I trust evolution will take of those folk.) 
&lt;/p&gt;
&lt;p&gt;
So if your abstractions are leaky, in that they are going to have strange interactions
with each other under-the-hood, then you should quickly start developing an understanding
of what happens under the abstractions you are given. Your effectiveness as a developer
becomes proportional to your understanding of what happens under the surface. Hence
the "defective" C++ books are a useful read. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=51b8b6a5-9c64-4075-945f-be87253c27a5" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,51b8b6a5-9c64-4075-945f-be87253c27a5.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=05e90db2-910e-4190-88ce-16092b5cf9b5</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,05e90db2-910e-4190-88ce-16092b5cf9b5.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,05e90db2-910e-4190-88ce-16092b5cf9b5.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=05e90db2-910e-4190-88ce-16092b5cf9b5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today Aziz mailed me a build of his Ikarus compiler for Windows. Though I don't have
much to do with software as such these days, I was excited. Ikarus is Aziz's Scheme
Compiler. I use Petite Chez Scheme on my machine. Petite  is Kent Dybvig's Scheme
interpreter, part of the Chez Scheme compiler system. I don't have Chez Scheme itself
because it sells, I am told, for several thousands of dollars and hence I cant afford
it. I expect Ikarus to be comparable to full Chez in many ways and surpass most other
Scheme systems out there. 
</p>
        <p>
What Aziz sent me was a zip file that extracted to a 128k exe and 4mb "boot" file.
He says the boot file says the same between windows, linux and mac. The bootstrap
executable changes. This is amusing because the "boot" file is actually the compiler
binary. It contains the compiled x86 code.  He able to get away with this because
he only relies on the OS to load his little bootstrap exe. After that point he simply
allocates memory pages from the OS and relies on the OS for almost nothing that he
can do himself. So the exe loads the boot file into memory which then acts as its
own loader, sets up its own stack, lays out its own code and data areas, does its
own GC and such. 
</p>
        <p>
Of course, all of this is written in Scheme itself. There is probably a small C file
somewhere that acts as the main() and the initial call into some ASM code that transfers
control to Scheme. Fun fun. 
</p>
        <p>
I have talked to Aziz about many parts of this system and almost always the design
has seemed to be of very high quality. His management of code objects, the runtime
stack, continuations and on and on. The system has a large part of R6RS implemented
and is already a superset of R5RS as far as I understand. Depending on how the development
process stabilizes (after all, this is all one persons implementation), I might move
over Ikarus altogether and maybe use it exclusively.  
</p>
        <img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=05e90db2-910e-4190-88ce-16092b5cf9b5" />
      </body>
      <title>Got a build of Ikarus</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,05e90db2-910e-4190-88ce-16092b5cf9b5.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2007/10/17/GotABuildOfIkarus.aspx</link>
      <pubDate>Wed, 17 Oct 2007 03:49:16 GMT</pubDate>
      <description>&lt;p&gt;
Today Aziz mailed me a build of his Ikarus compiler for Windows. Though I don't have
much to do with software as such these days, I was excited. Ikarus is Aziz's Scheme
Compiler. I use Petite Chez Scheme on my machine. Petite&amp;nbsp; is Kent Dybvig's Scheme
interpreter, part of the Chez Scheme compiler system. I don't have Chez Scheme itself
because it sells, I am told, for several thousands of dollars and hence I cant afford
it. I expect Ikarus to be comparable to full Chez in many ways and surpass most other
Scheme systems out there. 
&lt;/p&gt;
&lt;p&gt;
What Aziz sent me was a zip file that extracted to a 128k exe and 4mb "boot" file.
He says the boot file says the same between windows, linux and mac. The bootstrap
executable changes. This is amusing because the "boot" file is actually the compiler
binary. It contains the compiled x86 code.&amp;nbsp; He able to get away with this because
he only relies on the OS to load his little bootstrap exe. After that point he simply
allocates memory pages from the OS and relies on the OS for almost nothing that he
can do himself. So the exe loads the boot file into memory which then acts as its
own loader, sets up its own stack, lays out its own code and data areas, does its
own GC and such. 
&lt;/p&gt;
&lt;p&gt;
Of course, all of this is written in Scheme itself. There is probably a small C file
somewhere that acts as the main() and the initial call into some ASM code that transfers
control to Scheme. Fun fun. 
&lt;/p&gt;
&lt;p&gt;
I have talked to Aziz about many parts of this system and almost always the design
has seemed to be of very high quality. His management of code objects, the runtime
stack, continuations and on and on. The system has a large part of R6RS implemented
and is already a superset of R5RS as far as I understand. Depending on how the development
process stabilizes (after all, this is all one persons implementation), I might move
over Ikarus altogether and maybe use it exclusively.&amp;nbsp; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=05e90db2-910e-4190-88ce-16092b5cf9b5" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,05e90db2-910e-4190-88ce-16092b5cf9b5.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=dac5e645-ea48-4ef2-bfe9-eaf3e01158f4</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,dac5e645-ea48-4ef2-bfe9-eaf3e01158f4.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,dac5e645-ea48-4ef2-bfe9-eaf3e01158f4.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=dac5e645-ea48-4ef2-bfe9-eaf3e01158f4</wfw:commentRss>
      <title>Breadth First Tree Traversal with Braiding Yields</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,dac5e645-ea48-4ef2-bfe9-eaf3e01158f4.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2006/06/15/BreadthFirstTreeTraversalWithBraidingYields.aspx</link>
      <pubDate>Thu, 15 Jun 2006 18:48:43 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One of the solutions that did not make it into my yield
paper (though I sort of liked it) was one that used “braiding”.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The problem here is to do a breadth first traversal
of a binary tree. I was looking for a solution using my pet control operator yield.
The braiding solution occurred to some months back as a consequence. The solution
that finally made it into the paper was one based on a more traditional queue based
breadth first traversal (BFT from now on) which did have better perf than the braiding
solution. I am however documenting the braiding solution here because I think its
elegant at some level. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So how would one do a BFT of a binary tree? &lt;/font&gt;&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,3907b1ec-2d39-4639-8dd1-443e4aa0b234.aspx"&gt;&lt;font face=Arial&gt;Look
at this entry&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; for a slightly more detailed
problem description. Simple, we start out by defining braiding. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Say you have two yield based iterators. These are just
computations that yield values during their process of evaluation. These iterators
yield values of type &lt;b style="mso-bidi-font-weight: normal"&gt;Maybe.&lt;/b&gt; For those
unfamiliar with the Haskell type “Maybe”, here is a definition – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;data
Maybe a = Just a | Nothing&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It simply says that a value of type maybe is either
some actual value or the special value nothing. If you desperately need an analog,
think of it as a pointer or a reference – it either points to some object or its null. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So a stream of maybe-values looks like this &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;x1 x2 # x3 x4 x5 # # x6 # ..&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;where the ‘x’ denote actual values and the # denotes
occasional ‘Nothing’. If one had two such streams of values, then one can braid them
as follows. Consider the stream of xs’ and the stream of ys.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;x1 x2 # x3 x4 x5 # # x6 # ..&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;y1 # y2 y3 # y4 y5 # y6 y7 # ..&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;On braiding gives a single stream with that switches
between the original streams every time it sees a Nothing. This results is a single
stream like this – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;x1 x2 y1 # x3 x4 x5 y2 y3 # y4 y5
# x6 y6 y7 # ..&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is how braiding works. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So how does one do a BFT? Simple, one recursively traverses
the tree as follows – &lt;/font&gt;
&lt;/p&gt;
&lt;ul style="MARGIN-TOP: 0in" type=disc&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font face=Arial color=#000000&gt;If you are at a leaf, yield the leaf value and then
yield a Nothing. &lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font face=Arial color=#000000&gt;If you are at a branch, yield the branch value, a Nothing
and then braid the iterators of the left and right branches. &lt;/font&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Simple – that’s a breadth first traversal. If you look
at the algorithm closely you will realize that final stream produced will be in the
breadth first order but will also contain occasional Nothing values – the Nothing
values will be precisely in the those places when values of one level deeper in the
tree are being produced. (Of course, you don’t want to expose the Nothings you can
add a filter and remove them). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The other important observation, which is also a requirement
of the problem, is that the values used to resume the iterator will be available to
the branches or leafs that yielded the corresponding value – hence tree reconstruction
is trivial. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
This a breadth first tree walk that reconstructs the tree from the 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
the return values of the yield. It is expands the tree one level at 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
a time and internally uses Nothing to communicate level changes.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;bfTreeWalk
:: Tree a -&amp;gt; Yield i a (Tree i)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;bfTreeWalk
tr = suppressMaybe $ bft tr&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;where&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bft
(L v) = do (Just v') &amp;lt;- yield (Just v);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;yield
Nothing; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
(L v')&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bft
(B v t1 t2) = do (Just v') &amp;lt;- yield (Just v);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
Nothing;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;(t1',t2')
&amp;lt;- braidMaybe (bft t1)(bft t2);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
(B v' t1' t2')&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is the tree walk in Haskell. Even if you are not
able to run or fully grok the Haskell code above, you should be able to use it as
a guide to reconstruct the solution in your pet language. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The supporting braid and suppress functions are below
– &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
Convert maybe values into real values by ignoring the Nothing. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
1 2 10 # 3 30 # 5 6 70 50 # 8 ...&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
Becomes&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
1 2 10 3 30 5 6 70 50 8 ...&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;suppressMaybe
:: Yield (Maybe i) (Maybe o) r -&amp;gt; Yield i o r&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;suppressMaybe
yb = runMapY yb sM&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;where&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sM
Nothing = return Nothing&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sM
(Just v) = do r &amp;lt;- yield v;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
(Just r)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
Alternates two iterators, every time one yields a Nothing&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
1 2 # 3 # 5 6 # 8 ....&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
10 # 30 # 70 50 # 80 ....&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
and makes (where # is a Nothing)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: navy"&gt;&lt;font face="Courier New"&gt;--
1 2 10 # 3 30 # 5 6 70 50 # 8 .. 80 ... ....&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;braidMaybe
:: Yield (Maybe i) (Maybe o) r&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;-&amp;gt;
Yield (Maybe i) (Maybe o) r -&amp;gt; Yield (Maybe i) (Maybe o) (r, r)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;braidMaybe
yb1 yb2 = bM (runYield yb1) (runYield yb2) True&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;where&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bM
(Iterator (Just v) k) it ord = do i &amp;lt;- yield (Just v); bM (k i) it ord&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bM
it1 it2 False = do yield Nothing; bM it2 (resume it1) True&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bM
(Iterator Nothing k) it True = bM it (k Nothing) False&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bM
(Done v1) (Done v2) True = return (v1, v2)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bM
(Done v) it True = bM it (Done v) False&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;resume&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(Iterator
Nothing k) = (k Nothing)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;resume
it = it&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;The code above uses a monadic yield implementation
and can as easily be expressed by any language which supports a good yield operator. &lt;i style="mso-bidi-font-style: normal"&gt;(As
of now I have a yield implementation for Haskell and Scheme and I believe Sid has
ones for Python and Ruby (?))&lt;/i&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;At this point I should note that I was referred to
the naïve implementation of BFT using nested lists by Simon Peyton Jones. The cods
is below&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;breadthFirstTW
:: Tree Int -&amp;gt; [Int]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;breadthFirstTW
t = concat (bft t)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;where&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bft
:: Tree a -&amp;gt; [[a]]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bft
(L x) = [[x]]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bft
(B t1 t2) = b_zip (bft t1) (bft t2)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;b_zip
:: [[a]] -&amp;gt; [[a]] -&amp;gt; [[a]]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;b_zip
[] ys = ys&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;b_zip
xs [] = xs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; mso-bidi-font-size: 12.0pt"&gt;&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;b_zip
(x:xs) (y:ys) = (x++y) : (b_zip xs ys)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The essential idea behind the braiding traversal is
not very different from that of the nested solution with the operational encoding
of nested lists using Maybe. However looking at the nested list solution, at this
point, it is not apparent to me how it can be extended to reconstruct the tree. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font face=Arial color=#000000&gt;The implementation
of the monadic yield that this relies on is documented in my paper which I hope to
put up on my &lt;/font&gt;&lt;a href="http://www.cs.indiana.edu/~rpjames/"&gt;&lt;font face=Arial&gt;academic
website&lt;/font&gt;&lt;/a&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt; soon enough. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=dac5e645-ea48-4ef2-bfe9-eaf3e01158f4" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,dac5e645-ea48-4ef2-bfe9-eaf3e01158f4.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=8a79bbf8-b42a-4636-a738-cda2b133e3bc</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,8a79bbf8-b42a-4636-a738-cda2b133e3bc.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,8a79bbf8-b42a-4636-a738-cda2b133e3bc.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=8a79bbf8-b42a-4636-a738-cda2b133e3bc</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font color="#000000">I was attending a talk by Andrew Kennedy today when I heard
that Rotor 2.0 has been released. So it has the Shared Source version of the cool
new C# compiler and such. Fun Fun. </font>
        </p>
        <p>
          <a href="http://msdn.microsoft.com/net/sscli/">Download</a>
        </p>
        <img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=8a79bbf8-b42a-4636-a738-cda2b133e3bc" />
      </body>
      <title>Rotor 2.0</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,8a79bbf8-b42a-4636-a738-cda2b133e3bc.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2006/06/12/Rotor20.aspx</link>
      <pubDate>Mon, 12 Jun 2006 17:22:49 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font color=#000000&gt;I was attending&amp;nbsp;a talk by Andrew Kennedy today when I heard
that Rotor 2.0 has been released. So it has the Shared Source version of the cool
new C# compiler and such. Fun Fun. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/net/sscli/"&gt;Download&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=8a79bbf8-b42a-4636-a738-cda2b133e3bc" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,8a79bbf8-b42a-4636-a738-cda2b133e3bc.aspx</comments>
      <category>Languages</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=3907b1ec-2d39-4639-8dd1-443e4aa0b234</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,3907b1ec-2d39-4639-8dd1-443e4aa0b234.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,3907b1ec-2d39-4639-8dd1-443e4aa0b234.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=3907b1ec-2d39-4639-8dd1-443e4aa0b234</wfw:commentRss>
      <title>Work at MSRC – Haskell, GC, Papers</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,3907b1ec-2d39-4639-8dd1-443e4aa0b234.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2006/06/05/WorkAtMSRCHaskellGCPapers.aspx</link>
      <pubDate>Mon, 05 Jun 2006 21:42:30 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Work at MSRC has been moving slowly, though I have
been busy. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Parallel
GC for Haskell&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Not much to say on the Haskell parallel GC front except
that I am yet to actually start writing any code. I have been trying to understand
the existing code base and it has been a little over whelming. This is certainly not
one of the best code bases that I have seen. Actually quiet far from it. There are
functions of several hundred lines in length. The main GC function itself is 800+
lines long. I have been told that several people have got their PhDs of that GC.c
file. I was expecting a pure functional language to contain a couple of core object
types and everything else to be built around them. Far from it, there are 70+ types
of objects in the system – they have special cased almost everything they can think
of for efficiency sakes. Being a pure lazy language these things matter I guess. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;That aside the source is littered with lots of interesting
ideas. The problem with something so interconnected is that its hard to build incrementally
on this. So I am little stuck. The GC has a copy collector and a mark compact collector
in the same code base – they share a large amount of code. For a long time this confused
me. The system switches from a copy collector to a mark compact collector depending
upon memory usage of every step of every GC. The number of generations is runtime
configurable. The number of steps per generation is runtime configurable. It’s a crazy,
interesting system. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I have been making some notes over here, which I hope
to continue updating over the period of my internship – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://cvs.haskell.org/trac/ghc/wiki/GarbageCollectorNotes"&gt;&lt;font face=Arial&gt;http://cvs.haskell.org/trac/ghc/wiki/GarbageCollectorNotes&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Papers
- Quantum&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;That
aside, I helped complete – or rather didn’t help complete – a paper on Quantum Computing
since I landed in 
&lt;st1:City w:st="on"&gt;
&lt;st1:place w:st="on"&gt;Cambridge&lt;/st1:place&gt;
&lt;/st1:City&gt;
. I actually didn’t do much for that paper. I had some interesting ideas, but they
remained undeveloped enough to not go into the final paper (though we initially thought
it would). So well, in some sense my first paper is not really my first paper. :)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Papers
- Yield&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I finished my second paper since landing at 
&lt;st1:place w:st="on"&gt;
&lt;st1:City w:st="on"&gt;Cambridge&lt;/st1:City&gt;
&lt;/st1:place&gt;
this past weekend. The paper is about yield, (yes, finally!). It is coauthored with
Simon Peyton Jones and Amr Sabry, though most of the actual writing was done by me.
So in many senses this paper will not be of comparable caliber to most Amr Sabry or
Simon Peyton Jones papers. Writing this paper was quiet an experience – as it is,
it was my first real paper. Usually, I am told, people don’t write their first papers
completely themselves, they write a section or so. Secondly I had the names of two
very respected computer scientists on this and I was afraid of writing accidental
stupidity. They however did give me lots of comments over email. And at the end of
it I think I have come out braver, a tab bit less afraid of writing papers. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The paper has been submitted to the Haskell Workshop
2006. Haskell is probably the most difficult language to suggest a new control flow
operator. Being the pinnacle of pure functional programming, with monads and lazy
evaluation it is a very very hard language to make a value proposition to in terms
of adding control flow operators. All the same, I think we may have one or two interesting
arguments in favor of yield. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Breadth
First Renumbering&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;As an example of control flow based on lazy evaluation
consider this problem: You are given a binary and asked to renumber the nodes in breadth
first order, thus creating a new tree of the same structure but with changed node
values. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;
&lt;v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"&gt;
&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;
&lt;v:formulas&gt;
&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;
&lt;/v:formulas&gt;
&lt;v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"&gt;&lt;/v:path&gt;
&lt;o:lock aspectratio="t" v:ext="edit"&gt;&lt;/o:lock&gt;
&lt;/v:shapetype&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;img src="http://www.thinkingms.com/pensieve/content/binary/bft_tree1.jpg" border=0&gt;&amp;nbsp;&lt;/span&gt;to &lt;img src="http://www.thinkingms.com/pensieve/content/binary/bft_tree2.jpg" border=0&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Think about it. See if you can do this by only one
traversal of the tree and use constant space etc. Basically the best solution you
can think up. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In Haskell, lazy evaluation is used as a control flow
operation. But one that is an implicit control flow operation – in the sense that
the programmer doesn’t have to specify the order of evaluation the system will figure
it out, driven by need. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is the lazy Haskell solution - &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;data
T a = B a (T a) (T a) | L a&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;deriving
Show&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;bfn
:: ([Int], T a) -&amp;gt; ([Int], T Int)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;bfn
(k : ks, L a) = (k + 1 : ks, L k)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;bfn
(k : ks, B x a b) = (k+1 : ks'', B k a' b')&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;where
(ks', a') = bfn (ks, a)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;(ks'',
b') = bfn (ks', b)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;bfnum
:: T a -&amp;gt; T Int&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;bfnum
t = t'&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;where
(ks, t') = bfn (1 : ks, t)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It is just mind boggling that something like this can
work – and work so perfectly. If you know how to read Haskell and you haven’t seen
this solution before, get ready for a mild surprise. :) The implementation is adapted
from the appendix of Chris Okasaki’s&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;paper
– &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://portal.acm.org/citation.cfm?id=351253&amp;amp;dl=ACM&amp;amp;coll=ACM"&gt;&lt;font face=Arial&gt;http://portal.acm.org/citation.cfm?id=351253&amp;amp;dl=ACM&amp;amp;coll=ACM&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Even if you don’t understand Haskell, try to solve
this in your pet language and see what you come up with. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Haskell&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Since I am in a mood for writing a bit – here is a
little bit about Haskell. A tiny tiny intro. Haskell is a pure functional language.
If you don’t know what that means, there is good chance that you haven’t seen one
before. Also Haskell is one of the few languages that are lazy evaluated. Values are
computed only on a need basis – hence one gets to write all sorts of crazy circular
dependencies between function parameters and their results – if one is careful. Also
it is strongly typed – Haskell is a laboratory for stuffy of type systems, if nothing
else. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Lets do some examples. Immediately following the example,
I write what it means. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;n = 5&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;n is a function that takes no parameters and returns
the value 5. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;f n = n+1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;f is a function that takes one parameter, namely n
and return n+1. Hence if one writes (f 1) it is the equivalent of calling f with the
parameter 1 and will return 2. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you write code like the above, it will work. But
usually people write the types of everything they write. If you miss out the types,
Haskell has a type inferencer which will automatically figure out the types (and might
occasionally complain if there are ambiguities). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So here is the definition of the function f with its
type signature. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;f :: Int -&amp;gt; Int&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;f n = n+1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So the type of f is written by putting two colons after
f and is “from Int to Int”. In other words the function f takes an Int and returns
an Int. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is the type of the function even, a function that
checks if a number is even. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;even :: Int -&amp;gt; Bool&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It takes an Int and returns a Bool. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So what is the type of the function n? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;n :: Int&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;n = 5&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Simple? The type of n is simply Int.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is a function g that takes two parameters, namely
x and y and returns their sum. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;g :: Int -&amp;gt; Int -&amp;gt; Int&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;g x y = x+y&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The type says that g takes an Int and yet another Int
and returns an Int. The value of (g 5 10) is 15. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The interesting this is that in haskell, unlike in
many other languages, the expression (g 5)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;by
itself has a meaning. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;g5 :: Int -&amp;gt; Int&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;g5 = g 5&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;(g 5)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;is
a function that takes an Int&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;and returns
an Int. Here I assigned the name g5 to be (g 5) hence is I say (g5 20) the result
will be 25. The general idea behind applying only some of the parameters of a function
thereby result in a new function that awaits the remaining argument is called “currying”
– named after Haskell B Curry. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Does this interest you? If so you should consider reading
up about Haskell a bit. Maybe I will drop a few simpler examples of lazy evaluation
based niceties sometime. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=3907b1ec-2d39-4639-8dd1-443e4aa0b234" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,3907b1ec-2d39-4639-8dd1-443e4aa0b234.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=4a1b3272-4f4b-4c98-a855-6066fca67d87</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,4a1b3272-4f4b-4c98-a855-6066fca67d87.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,4a1b3272-4f4b-4c98-a855-6066fca67d87.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=4a1b3272-4f4b-4c98-a855-6066fca67d87</wfw:commentRss>
      <title>Yield Lang 1.0 and Haskell</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,4a1b3272-4f4b-4c98-a855-6066fca67d87.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2006/03/03/YieldLang10AndHaskell.aspx</link>
      <pubDate>Fri, 03 Mar 2006 07:37:42 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;Why
Haskell?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So how long does it take for a completely fledgling
Haskell programmer to implement a weird language? 2 nights. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Its pretty amazing if you think about it – and it fun
and not stressful as well. If I did as much in C or Cpp it would have been significantly
more stressful and would have take a over a weekend for sure. And even after that
it wouldn’t be as flexible as this is. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In some sense, in my current limited opinion, Haskell
is to Scheme what Ruby is to C++. To add to it, it is purely functional than scheme,
is lazy, comes with A REAL library, allows for pattern matching and discriminated
unions etc… the goodness goes on – as matter of fact, it can even pretend to be imperative
for a bit. Also, GHC generates actual Win32 exes that I can run. If you are a languages
person you might think it’s a moot point, but for someone who likes to build tools
and wants to sometimes share them with his (less inclined) friends, this is essential. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So I think Haskell is going to takes its place in my
bag of tools. The only thing I really miss from Scheme land are macros. I wish Haskell
had macros – better, I wish Haskell had multistage evaluation. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Being a almost ‘pure’ imperative programmer when I
joined college, Prof Dan Friedman’s Programming languages class hurt my head really
badly. And I was coming to terms with functional programming. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Last semester I also took a class with Prof Amr Sabry
– Quantum computing – and this was my first real introduction to Haskell. I am working
with him this semester and of late I have been trying to understand Monads. Its one
thing to have working knowledge of a concept, and its quiet another to formally study
it. Monads hurt like few other things hurt before – and the fact is that it makes
you look at imperative programming in this totally other way.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So that’s the context for why this is in Haskell. The
blog entry is really about this little language I wrote in .. in all fairness a little
more than a late night. And I haven’t used the parser generator or other tools before
this. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Yield
Language 1.0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So whats the language like? Well, you’re not going
to want to use it at all. But all the same it is the lambda calculus with the following
additions (some of which take away its purity) – yield (with all the right behavior
in place), if-then-else, numbers (+, -, ==), strings (+, ==). In other words, it’s
a simple higher order language with strings and numbers and fancy control flow operator
called yield, which is the only “impure” part of the language. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;To support yield I introduce a funny tagging operator
I call ‘pi’ to tag a sub-expression that can yield. A pi-expression can be called
like a normal application, or can be used as a coroutine using co, next and run. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The actual internal implementation is what is best
described as “stackless”.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;f
= \x -&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;((("x
= " + x) + ", ") + 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;if
(x == 0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;"zero"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;"not
zero");&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;(f
10)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This evaluates and returns “x = 10, not zero”&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Basic syntax &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;e = &lt;span style="mso-tab-count: 1"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;\x-&amp;gt;e &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;| x &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;| e1 e2&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;| if e1 e2 else e3&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;| (e1 + e2)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;| (e1 – e2)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;| (e1 == e2)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;| &amp;lt;num&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;| &amp;lt;string&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;| x = e1; e2&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The above syntactic categories as basically all pure.
The last rule is a let. There is no fixed point operator and you will need to add
one of your own to do recursion. Evaluation is strict, applicative order. The following
are the extensions for yield support.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;|
pi e&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;|
yield e&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;|
co e&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;|
next e1 e2&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;|
run e1 as x1 x2 -&amp;gt; e2 or x3 -&amp;gt; e3&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Some more examples, assume that we have an applicative
order Y combinator called “fix”.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;-- Applicative Y combinator&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;fix = \f -&amp;gt; ((\x -&amp;gt;
(f \y -&amp;gt; ((x x) y))) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(\x
-&amp;gt; (f \y -&amp;gt; ((x x) y))));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;is
a relatively simple function that takes a number and yields as many times. I have
used the fixed point operator so that I can loop inside the pi block.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;-- An iterator that yields
'x' times&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;iter = \x -&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(pi&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(((fix
\loop -&amp;gt; \x -&amp;gt; \s -&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if
(x == 0)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;s 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else
v = yield x; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 4"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((loop
(x-1)) (v+s)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;x)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One can call this function in two ways – simple invocation
– &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;((iter 1000) \x-&amp;gt;(x+x))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Or using the coroutine-like behavior, that is sometimes
called external-iterators or generators.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;call = (fix&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(\call
-&amp;gt; \c -&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;run
c&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;as
(x1 x2) -&amp;gt; (call (next x2 (x1 + x1)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;or
x1 -&amp;gt; x1));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;v1 = (call (co (iter 1000)));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So one can save the following code into a file and
execute it from command line using the command – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;langy.exe &amp;lt; filename.txt&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;[update: made some simple syntactic niceties to the
language]&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;--
Applicative Y combinator&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;fix
= \f -&amp;gt; (\x -&amp;gt; (f \y -&amp;gt; (x x y)) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;\x
-&amp;gt; (f \y -&amp;gt; (x x y)));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;--
An iterator that yields 'x' times&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;iter
= \x -&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(pi&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;((fix
\ loop x s -&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if
(x == 0)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;s 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else
v = yield x; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(loop
(x-1) (v+s)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;x
0));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 4"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;--
Call will invoke an iterator any number of times&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;--
At each point it thunks the return value and then uses that as the 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;--
next value paramter.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;call
= (fix&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;\ loop c -&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;run
c 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;as
x1 x2 -&amp;gt; (loop next x2 (x1 + x1))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;or
x1 -&amp;gt; x1);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;v1
= (call co (iter 1000));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;v2
= (iter 1000 \x-&amp;gt;(x+x));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;("Values
are " + v1 + ", " + v2)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;And this outputs – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;"Values are 1001000, 1001000"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/content/binary/langy.zip"&gt;&lt;font face=Arial&gt;Downloads&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=4a1b3272-4f4b-4c98-a855-6066fca67d87" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,4a1b3272-4f4b-4c98-a855-6066fca67d87.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=e3f15d2d-0de3-4259-a476-e295a24dc850</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,e3f15d2d-0de3-4259-a476-e295a24dc850.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,e3f15d2d-0de3-4259-a476-e295a24dc850.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=e3f15d2d-0de3-4259-a476-e295a24dc850</wfw:commentRss>
      <title>Programming with Trampolines, Pipelines and Pi – 2</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,e3f15d2d-0de3-4259-a476-e295a24dc850.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2006/03/01/ProgrammingWithTrampolinesPipelinesAndPi2.aspx</link>
      <pubDate>Wed, 01 Mar 2006 01:02:14 GMT</pubDate>
      <description>&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt; 
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;(A much delayed part 2. &lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,08fca7b1-6e50-4650-b3ed-68f950d04afe.aspx"&gt;Previous
article is here&lt;/a&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt; 
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Pipelines&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This article primarily describes the pipeline construct.
The simplest way to describe a pipeline is to say the way the trampoline models the
interaction between a caller and iterator and, the pipeline models a call tree. One
can think of a pipeline as a cascade of trampolines. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Suppose one had a call tree where each frame in the
call tree corresponded to that of an iterator. As each iterator yields or returns
to a yield, what the program effectively does is that it moves values up and down
the call tree. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Consider the following function – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;def
bits(n)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if
n == 1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bits(n-1){|v|&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
v*2&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
v*2+1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here invoking bits with a value n, causes it to yield
every possible n-bit binary number. Now this sort of thing is not easy to model with
a trampoline. A trampoline lets one process in the trampoline act as a iterator and
the other as a caller (though the device itself does not introduce an asymmetry). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;To do something equivalent to code snippet above, one
needs to maintain a chain of iterators. How does control transfer between iterators
in call chain, assuming that none of the iterator return? Control can move up and
down the call tree corresponding to when a caller returns the value to a yield statement
higher up the tree OR the iterator can yield a value to a caller further down the
tree. Something like &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;the diagram below
– each up arrow being a return to a yield called by a block on top and each down arrow
being a yield. (The direction of the arrow indicates which way control transfers.)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;img height=259 alt=pipe-call-tree.gif src="http://www.thinkingms.com/pensieve/content/binary/pipe-call-tree.gif" width=137 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The pipeline device gives every process in it to communicate
with the process to the left of it or to the process to the right of it. One can choose
a convention here where the process to the left of a process can be considered it
callee and the process to the right can be considered its caller. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The picture below gives a comparison of what the pipeline
device does. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;img height=276 alt=pipe-device.gif src="http://www.thinkingms.com/pensieve/content/binary/pipe-device.gif" width=138 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Every process in a pipeline device is created using
a lambda-pipe. A lambda-pipe, unlike the lambda-iter, makes available the binding
‘left’ and ‘right’ in the scope of its body. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A process can call left to pass control to the process
to its immediate left. It can call righ to pass control to its immediate right. The
‘left’ and ‘right’ are similar to the yield in the sense that they take a parameter
and return a value. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If a process in a pipe, executes a right with a values
‘v’, the value is made available to a process to its left as the returned value of
a ‘left’ executed by it. Hence left and right alls by the process have to match up
to facilitate control flow. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is the basic idea behind the pipeline device.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Example:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Consider the following function basis, which is basically
a rewrite of bits, but for usage in a pipe.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(define basis&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda-pipe
()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
((v (left)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(eq? v 'end) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(right
'end)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(begin&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(right
(cons #f v))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(right
(cons #t v))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(yield-all
(basis)))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;One can put multiple instances of basis into
a pipe and have an initial process that will start the cascade by right yielding a
empty list, immediately followed by the end marker. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(foreach
(command-shell-pipeline (gen-pipe '() 'end)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(basis)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(basis)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(basis))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(printf
"num: ~a~n" (port-value it))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This produces – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;num: (#f #f #f)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;num: (#t #f #f)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;num: (#f #t #f)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;num: (#t #t #f)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;num: (#f #f #t)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;num: (#t #f #t)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;num: (#f #t #t)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;num: (#t #t #t)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;num: end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In the above code a gen-pipe, will simply right yield
each of it arguments in the same order. One may notice that I use the command-shell-pipeline
in a foreach, which means that it is itself an iterator. The pipe device wraps values
in something called a ‘port’, to extract the value from the port, one uses the port-value
function. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;The Pipe
device is an iterator:&lt;/b&gt; To understand why the command-shell-pipeline is itself
an iterator (while trampoline is not) one has to look at the diagram above for the
pipe device. The left yield of the left most process (or topmost depending on how
you look at it) and the right yield of the right most process are yields that transfer
control outside of the pipe device. Hence the pipe device itself is an iterator. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;o:p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;i style="mso-bidi-font-style: normal"&gt;[updated] &lt;/i&gt;The
interesting thing about the pipeline is that each process in the pipeline gets state
management for free. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The pipe device lets you build only a linear data structure,
in the sense that each process in the pipe can only communicate with its left and
right neighbors. One can use pipe nested in other pipes or in trampolines to make
arbitrarily complex control flow structures. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Caveats:&lt;/b&gt; In
retrospect, to be honest, I haven’t really used the pipe much in actual code. It was
created more to fill a missing link in the usage of yields that a device than out
of practical usage patterns. One might actually resort to nesting trampoline usages
more often that one might use the pipe. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Also, the more I think about this device I can see
more than one ‘correct’ behavior in the model that it presents to the user which sometimes
makes it rather un-intuitive to program with. Desipte this it is easy to see how many
problems can be implemented as a pipeline of filters that can each maintain state
and back track. I need to try and express more problems with the pipe to see how well
they can be expressed. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Due to some of these concerns the code for the actual
pipe device implementation, takes as a parameter a ‘semantics’ function so that the
user can describe the behavior required from the pipe externally. One predefined pipe
available is what I have called the command-shell-pipe. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am also interested in finding analogous constructs
to this – one of the things that I should look at is a non-determinism monad used
with a monad for state threads. The processes in the pipeline device are similar to
what is described as an ‘online transducer’ by Olin Shivers and Matthew Might in &lt;/font&gt;&lt;a href="http://www-static.cc.gatech.edu/~shivers/papers/fcoro.pdf"&gt;&lt;font face=Arial&gt;Continuations
and Transducer Composition&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. After putting
this up online I see that the transducers are studied in detail by many people. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/content/binary/yield-pack.zip"&gt;&lt;font face=Arial&gt;Download
code.&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;/o:p&gt;
&amp;nbsp;&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=e3f15d2d-0de3-4259-a476-e295a24dc850" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,e3f15d2d-0de3-4259-a476-e295a24dc850.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=08fca7b1-6e50-4650-b3ed-68f950d04afe</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,08fca7b1-6e50-4650-b3ed-68f950d04afe.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,08fca7b1-6e50-4650-b3ed-68f950d04afe.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=08fca7b1-6e50-4650-b3ed-68f950d04afe</wfw:commentRss>
      <title>Programming with Trampolines, Pipes and Pi – part 1</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,08fca7b1-6e50-4650-b3ed-68f950d04afe.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2006/02/04/ProgrammingWithTrampolinesPipesAndPiPart1.aspx</link>
      <pubDate>Sat, 04 Feb 2006 06:26:54 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;This
is a series of blog entries that introduce three devices written using the yield operator
for Scheme. Previously I had the following entries that described the requisite features
of a complete yield operator and an implementation of such a yield operator for Scheme.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,21892608-a48c-414b-930f-d0ddecbc5b07.aspx"&gt;&lt;font face=Arial&gt;Yield
the Magnificent&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,65223f21-a4f5-4eea-8d17-6c191cc48a02.aspx"&gt;&lt;font face=Arial&gt;Yield
Implementation for Scheme&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Trampolines, Pipelines and Pi are programming devices
or constructs that are built on top of the yield and purely the functional subset
of Scheme. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;There are many ways one can look at the power provided
by the yield operator. One way to look at the yield is that it is a call-tree walker.
It can move information up and down the call tree. If the yield implementation is
sufficiently flexible, it can walk up and down several call-trees which exist concurrently. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Another way to look at the yield is to think of it
as adding input and output capabilities to a function in functional system. A function
during the process of computing its value changes state, creates temporary variables
etc. When the result or return value of the function is computed the state of the
function collapses and the value is returned. Yield offers a way for functions to
do input and out with other functions while they maintain state. More about this later. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Trampolines&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I want to start off by introducing the simplest of
the three devices, the trampoline – sometimes I refer to this construct as the trampoline
process as well. (Note: The name trampoline is used only in the context of the yield
based programming device I describe here and is not a logical extension of other trampoline
constructs you may have encountered before.)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The trampoline was introduced to address the following
scenario – in a purely functional context what is the meaning of a parameter code
block that is passed to an iterator cannot affect the caller’s state. Such a parameter
code block is always a closure, in a functional context. On invoking a closure, the
closure cannot maintain or modify state in the caller without resorting to some sort
of a side effecting operation such as an assignment.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The trampoline packages such a computational effect
so that the programmer need not think in non-functional terms when using the yield.
Instead of using a &lt;i style="mso-bidi-font-style: normal"&gt;set!&lt;/i&gt; or an assignment
as the computational effect, the trampoline device uses a jump as the computational
effect. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;To illustrate what I mean, one has to look at the relation
ship between the caller and a yielding callee in an imperative language. The flow
of control is almost always as follows for a Ruby or C# yield (yes, I am abstracting
out many details here) –&lt;/font&gt;
&lt;/p&gt;
&lt;ol style="MARGIN-TOP: 0in" type=1&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font face=Arial color=#000000&gt;caller calls iterator, control transfers to iterator&lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font face=Arial color=#000000&gt;iterator does some computation and produces a values,
yields it&lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font face=Arial color=#000000&gt;control transfers to caller, &lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font face=Arial color=#000000&gt;caller does something with the value – this something
is usually a side effect &lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;caller
returns a value to iterator, control transfers back to iterator&lt;/font&gt;&lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font face=Arial color=#000000&gt;steps 2 to 6 can repeat any number of times till the
iterator returns. &lt;/font&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The problem with this functional programming land is
that the there is no use in yielding the value if the caller cant to anything with
it – an alternative is pass an environment back and forth between the caller and iterator
or some such thing, which is always tedious to manage. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The trampoline does the following. The trampoline becomes
the caller for two functions, both of which are iterators that concurrently maintain
state. One iterator place the role of the caller in the imperative case and the other
one plays the role of the callee. Since the function playing the roles of the caller
is an iterator, its free to maintain any sort of local state it chooses. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The trampoline device is a simple device, but to see
the correct analogy that argues its purpose is a little tricky. Another way to look
at a trampoline is to look at it as two iterators such that when one yields control
passes to the other and when the other yields control passes back to the first. The
process terminates when one of the two iterators terminate.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;
&lt;v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;
&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;
&lt;v:formulas&gt;
&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;
&lt;/v:formulas&gt;
&lt;v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"&gt;&lt;/v:path&gt;
&lt;o:lock v:ext="edit" aspectratio="t"&gt;
&lt;img height=55 alt=yield-tramp-1.GIF src="http://www.thinkingms.com/pensieve/content/binary/yield-tramp-1.GIF" width=289 border=0&gt;
&lt;/o:lock&gt;
&lt;/v:shapetype&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is an example of code that uses the trampoline.
When the trampoline process terminates, a list of values that are the return (or last
yielded values) of both iterators is returned.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is an iterator that adds values that it gets yielding
the current sum at any point. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;(define
adder&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda-iter
()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
loop ((s 0))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(loop
(+ s (yield s))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is an iterator that yields the first ‘n’ Fibonacci
numbers&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;(define fibonacci&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda-iter
(n)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
loop ((a 1)(b 1)(n n))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(not (zero? n))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(begin&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(yield
a)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(loop
b (+ a b) (sub1 n)))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;To sum the first n Fibonacci numbers, one create a
simple trampoline between the iterators&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;(printf "Sum = ~a~n" 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cadr
(trampoline-process (fibonacci 10) (adder))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The cadr is there because the trampoline returns a
list of two values, the last value obtained from the Fibonacci and the last value
obtained from the adder. We are interested in the sum yielded by the adder and so
we take the cadr.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The trampoline process that is implemented in the library
that I have shared below is a slight generalization of this idea – the generalization
being that the trampoline process can take any number of iterators as arguments creates
a circular list of control transfer using yield. While having two iterators in a trampoline
can be thought of as the equivalent of an imperative caller and callee, there is no
simple parallel I can think of for three of more iterators in a trampoline. Below
is a diagram of trampoline with three iterators.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;img height=80 alt=yield-tramp-2.GIF src="http://www.thinkingms.com/pensieve/content/binary/yield-tramp-2.GIF" width=522 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I frequently use a trampoline while programming in
scheme using yield. While it may not be easy to see why trampolines are useful just
by using a simple example like the above, they useful in managing code complexity
when each of the iterators involved has to do a non trivial computation. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;As an example I wrote a CPS transformer for a subset
of scheme last semester, at the heart of which was a trampoline. One iterator would
recursively walk down the source expression tree and would yield out values. The other
iterator would reconstruct a CPSed expression. So it gives you the conceptual clarity
of writing a two pass CPSer while in effect only one pass happens. (Of course I could
mash both the analysis and construction phases into one big hairy ball of mutually
recursive functions, but that would not let me focus on one problem at a time and
possible build them up as reusable iterator components. This of course was a little
non traditional and might not have been easy on the evaluator of the assignment).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/content/binary/yield-pack.zip"&gt;&lt;font face=Arial&gt;Download
Sources for Yield, the Trampoline and the Sample Code above.&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In the next related entry I hope to discuss the Pipeline
device (aka the Pipe device).&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=08fca7b1-6e50-4650-b3ed-68f950d04afe" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,08fca7b1-6e50-4650-b3ed-68f950d04afe.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=46c670c3-639c-4817-b5f4-f459a25e5597</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,46c670c3-639c-4817-b5f4-f459a25e5597.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,46c670c3-639c-4817-b5f4-f459a25e5597.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=46c670c3-639c-4817-b5f4-f459a25e5597</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <title>What is the Y combinator?</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,46c670c3-639c-4817-b5f4-f459a25e5597.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2006/01/29/WhatIsTheYCombinator.aspx</link>
      <pubDate>Sun, 29 Jan 2006 05:57:21 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What is the Y combinator? I have seen lots of discussions
on the web but nothing that seemed like a simple explanation of how it works or why
it is needed. I finally understood the Y combinator a few days back and a lot of things
snapped in place. So here I will try and explain it from my perspective. In this entry
I am taking liberties with various syntaxes – please bear with me. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is the Y-combinator for a normal order lazy language
– &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;Y
= \f.((\x.(f (x x))) (\x.(f (x x))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;(Here, the ‘\’ denotes a lambda). Scheme is an applicative
order language and the above combinator cannot be used as such in scheme because it
will lead to an infinite expansion. More on this later.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Let’s start from some basics – say we are writing a
mathematical expression and we said &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;a = a + 1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;While the above means something in imperative programming
languages (like C), it does not mean anything in mathematics. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now say I want to write the factorial function in mathematics,
I would say something like this &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;fact(0) = 1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;fact(n) = n * fact(n-1)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;And this definition is perfectly valid. However you
notice that it is similar to the a = a + 1 expression in the sense that in describing
the value of something, we refer to that very thing. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This general principle, called a recursive definition,
has a problem in the context of pure functions (like the lambda calculus). The problem
is as follows – a function is a nameless entity – the only named entities that a function
can use are function’s parameters (the variables introduced by the function itself)
or parameters of a parent function that it is define in the scope of. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;For example &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(lambda (x y)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;;
can use x and y here&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(a)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;;
can use a, x and y here&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now for a recursive definition, a function needs to
be able to refer to itself (or like we say in some languages, a functions needs to
‘call’ itself). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So, the only way that one can define a recursive function
would be to receive the function itself as one of the functions arguments. Think about
this for a bit – if you are not used to programming in a language where you can pass
a function, or return a function as though it were a value (similar to how you treat
an integer), then this might be a hard idea. If you are from a programming background
that wherein you are used to ‘higher order’ programming, then I am only stating the
obvious here. (The general idea with higher order programming is that functions are
first class values, like integers – which means that they can be passed as arguments,
returned from functions, stored in data structures etc). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So we define a function such that it takes an additional
argument which is itself. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Lets say &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;factorial0(factorialx, n) =
if n == 0 then 1 else n * factorialx(factorialx, n -1) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;factorial(n) = factorial0(factorial0,
n)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Does this make sense? If it does not, then don’t bother
read further. You notice that the factorial0 function takes 2 arguments one of which
is the function itself. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Let me rewrite this in scheme-style syntax&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(let ((factorial0 (lambda (fact,
n) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(zero? n) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;1 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(*
n (fact fact (sub1 n)))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;(let
((factorial (lambda (n) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(factorial0
factorial n))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;;
I can use factorial here 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Make sense? Ok, so now let me write the interesting
function factorial0 as a nested lambda as follows - &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(lambda (fact) (lambda (n) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(if (zero? n) 1 (* n ((fact
fact) (sub1 n)))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You notice that fact is applied to fact, to generate
the inner lambda which is then invoked with n-1. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So now, suppose one has a handy function of the following
form&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;omega = (lambda (x) (x x))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One can define factorial as follows &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;(let
((factorial 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(omega
(lambda (fact) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(n) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(zero? n) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(*
n ((omega fact) (sub1 n)))))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;;
use factorial here 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;There you go – so now we have a way of defining recursive
function definitions even if your language did not directly allow a recursive definition. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So why do we need the Y combinator? You notice that
in the definition of factorial we had to do something that looks very strange in the
definition of the function – we call the function omega to return a function that
we can call. The Y combinator does away with this for us. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;To start thinking about the Y combinator, think about
things this way – suppose the parameter ‘fact’ was already ‘(omega fact)’ then we
wouldn’t have to call omega inside the definition of factorial correct. Right?&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If we wanted that we simply need to rewrite omega this
way right – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(lambda (x) (x (x x)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Such that the first parameter is already applied to
itself. But then this is not enough, because when the recursive call is made, the
second time the parameter is only fact and not (fact fact) or (omega fact). Well,
so we can fix this by having one more level in the definition of omega, such that
omega looks like this – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(lambda (x) (x (x (x x))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;But then the third time this would not be the correct
parameter… ideally we need an infinite application of x, because we don’t know how
many times the function will call itself. In other words the omega should look a little
like this &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(lambda (x) (x (x (x (x (x …
))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is exactly what the Y combinator does. To see
how it does this consider OMEGA defined as&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;OMEGA = (omega omega)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;(or expanding for little omega we get)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;OMEGA = ((lambda (x) (x x))
(lambda (x) (x x)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you haven’t seen this before, look at this device
for a bit – do you see how it is infinite self application? If you do then consider
the following&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;((lambda (x) (f (x x))) (lambda
(x) (f&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(x x)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It doesn’t matter what f is right now, but see what
this does. After one reduction this would look like this - &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(f (term term))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Where term = (lambda (x) (f (x x)))&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The second reduction would look like this and so on &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(f (f (term term)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(f (f (f (term term))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This, if you notice is similar to what we required
earlier, where instead of ‘f’ we used ‘x’. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is the basic mechanism for the Y combinator. And
the Y combinator is simply&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;Y = (lambda (f) ((lambda (x)
(f (x x))) (lambda (x) (f&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(x x)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So how do we define a recursive function using the
Y? Here is factorial&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(let ((factorial (Y (lambda
(fact)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(n) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;(if
(zero? n)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;1 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(*
n (fact (sub1 n)))))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;;
use factorial here&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Nice? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now in the beginning I said that this Y is the Y for
the last normal order language. Scheme is applicative order and non lazy. What that
means is that&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;if you use the Y combinator
defined above in scheme, during the definition of factorial it will try to do the
infinite expansion and will never terminate. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Instead one just eta-expands the definition to get
the applicative order Y combinator. Suppose you say that term is (lambda (x) (f (lambda
(y) ((x x) y))))&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;And we define the combinator as &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;Y = (lambda (f) (term term))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Then we have the applicative order Y that is usable
from scheme and other applicative order languages. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Look at its expansion to see what I mean &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;(f (lambda (y) ((term term)
y))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So the first parameter to ‘f’ (recursive function we
are interested in is a lambda – the application inside the lambda is done only if
f calls it.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Let me define both the Y combinators described here
in lambda form &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;Y = \f.((\x.(f (x x)) (\x.(f
(x x)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;Y = \f.((\x.(f (\y ((x x) y)))
(\x.(f (\y ((x x) y))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Once you see why the Y combinator is needed and you
understand omega – its easy to see what the Y is and how it useful in defining recursive
functions in a mathematically pure way. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The Y combinator is described as a fixed point function
or combinator. The idea is that is lets a function describe its behavior in terms
of itself until the function reaches a fixed point – like in the case of factorial
the function reaches 0 and does not need to recurse any more. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;References –&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://en.wikipedia.org/wiki/Y_combinator"&gt;&lt;font face=Arial&gt;http://en.wikipedia.org/wiki/Y_combinator&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.dreamsongs.com/NewFiles/WhyOfY.pdf"&gt;&lt;font face=Arial&gt;http://www.dreamsongs.com/NewFiles/WhyOfY.pdf&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Though
I myself had looked at the Y many times before I never really understood it until
I had to write recursive functions in the pure lambda calculus and I used omega to
do it. I then happened to mentioned to Prof Friedman that I did not understand the
Y and in a minute he set my thinking right. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I understand
that in the description above I have taken some liberties with syntax and something
are described in a hand wavy sort of way. However if you have suggestions about how
I can better explain this, let me know. Of course I require that you understand scheme
style syntax and higher order programming (at least minimally).&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=46c670c3-639c-4817-b5f4-f459a25e5597" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,46c670c3-639c-4817-b5f4-f459a25e5597.aspx</comments>
      <category>Languages</category>
      <category>Mathematics</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=04689bb5-4067-4a94-b3c5-f64f3fc36228</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,04689bb5-4067-4a94-b3c5-f64f3fc36228.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,04689bb5-4067-4a94-b3c5-f64f3fc36228.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=04689bb5-4067-4a94-b3c5-f64f3fc36228</wfw:commentRss>
      <title>Yet another Lambda Calculus Number and List encoding</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,04689bb5-4067-4a94-b3c5-f64f3fc36228.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2006/01/28/YetAnotherLambdaCalculusNumberAndListEncoding.aspx</link>
      <pubDate>Sat, 28 Jan 2006 06:56:34 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Some context – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The other day in Prof Dan Friedman’s Advanced Programming
Languages class we had an assignment where we had to write a lambda calculus interpreter
that did non deterministic application and we had to write the factorial in it. Also,
reduction was to continue even if the top level term was value. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;As
a consequence of working on this we were expected to discover a method of encoding
numbers using pure lambda terms. A really long time back 
&lt;st1:place w:st="on"&gt;
&lt;st1:PlaceName w:st="on"&gt;Alonzo&lt;/st1:PlaceName&gt;
&lt;st1:PlaceType w:st="on"&gt;Church&lt;/st1:PlaceType&gt;
&lt;/st1:place&gt;
(creator of the lambda calculus) created an encoding now called the Church numerals.
I created the following set when working on the factorial problem.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;t = \a.\b.a&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;true&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;f = \a.\b.b&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;false&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;zero = \x.t&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;zero? = \x.(x f)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;s = \x.\b.((b x) b)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;successor &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;p = \x.(x t)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;predecessor&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;(Like in Haskell the ‘\’ represent lambda). So we have
a way of saying zero, we have a way of checking if a number is zero and we have the
ability to add one and subtract one. That gives us all the natural numbers including
zero.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you notice, the predecessor define above returns
a value that is an invalid number when applied to zero. An alternate ‘type safe’ definition
is the following – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;p = \x.(((zero? x) x) (x t))&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;Here (p zero) is zero. &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now you may think that that’s not great way of implementing
numbers – its inefficient etc. Yes that’s true, but remember that the lambda calculus
is a formal system, it’s a mathematical formalism and hence has no notion of cost.
In the study of formal systems (other than the study of their complexity) we are interested
in asking questions about what the system can do and cannot do. The above encoding
I believe is equivalent to the encoding of Church numerals. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Following the definition of numbers, I can define ‘add’
in the following obvious way - &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;add = (Y \add.\a.\b.(((zero? a) b) ((add (p
a)) (s b)))&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here ‘Y‘ is the fixed point Y combinator and this is
equivalent to &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;add(a, b)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;{
if a == 0 then return b else return add(a - 1, b + 1) }&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Similarly one can define ‘mul’ and ‘factorial’ as well. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I went ahead and defined operators so that I have scheme/lisp
style lists. I am told that there are very similar to Church’s definitions. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;cons = &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;\x.\y.\b1.\b2.((b1
f) ((b2 x) y)) &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;car = &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;\ls.((ls
#f) #t) &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;cdr = &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;\ls.((ls
#f) #f) &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;null = &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;\x.x &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;null? = \ls.(ls #t)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Hence we have – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;(null? null) -&amp;gt; #t&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;(car null) -&amp;gt; undefined&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;(cdr null) -&amp;gt; undefined&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;(car (cons a b)) -&amp;gt; a&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;(cdr (cons a b)) -&amp;gt; b&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Can you shoot yourself in the foot using these definitions?
Of course you can – but if you are careful you can write meaningful programs as well.
To do other sorts of checks, like to prevent us from doing (s cons) we need some kind
of type system or validations rules – but these are not relevant to the discussion
of the pure lambda calculus. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is a basic lambda calculus reference - &lt;/font&gt;&lt;a href="http://en.wikipedia.org/wiki/Lambda_calculus"&gt;&lt;font face=Arial&gt;http://en.wikipedia.org/wiki/Lambda_calculus&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is a Church encoding reference - &lt;/font&gt;&lt;a href="http://en.wikipedia.org/wiki/Church_numeral"&gt;&lt;font face=Arial&gt;http://en.wikipedia.org/wiki/Church_numeral&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=04689bb5-4067-4a94-b3c5-f64f3fc36228" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,04689bb5-4067-4a94-b3c5-f64f3fc36228.aspx</comments>
      <category>Languages</category>
      <category>Mathematics</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=3abd9d48-cec9-478b-bccf-3072f2c3dd42</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,3abd9d48-cec9-478b-bccf-3072f2c3dd42.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,3abd9d48-cec9-478b-bccf-3072f2c3dd42.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=3abd9d48-cec9-478b-bccf-3072f2c3dd42</wfw:commentRss>
      <slash:comments>7</slash:comments>
      <title>FooGroup Algebra</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,3abd9d48-cec9-478b-bccf-3072f2c3dd42.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/12/08/FooGroupAlgebra.aspx</link>
      <pubDate>Thu, 08 Dec 2005 05:18:21 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;FooGroup
Algebra is a little ‘algebra’ that I created while trying to solve a problem. It seemed
sufficiently interesting to describe by itself. I would have liked to call it group
algebra, but it seemd like the name would already have been taken, and it also seemed
like that’s too nice a name to dedicate to something like this :)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;FooGroup
Algebra&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A term in this algebra consists of one or more symbols
enclosed in [] or (). An expression is a set of terms. The enclosing [] or () are
called the type of the term. The symbols the enclose are called base of the term.
The ordering of symbols inside a term is of no significance. The ordering of terms
in an expression is of no significance. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here are some expressions:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a
b c)[c d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a
b)(c d)(a d)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;An expression is said to be solved, if all the terms
in the expression have only one symbol. The following is a solved expression:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a)[b](c)(d)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The value of each symbol is the type of the term that
it is held. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;An expression is invalid or is a contradiction is there
atleast two terms of different type but same base. The following expressions are contradictions:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a b)[a b]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a)(b c d)[a]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Term
Reduction and Solving:&lt;/b&gt; One can solve and expression by reducing each term in the
expression until every terms contains only one symbol. Terms can be reduced as follows
– &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(X Y) =&amp;gt; (X)[Y] and [X](Y)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;[X Y] =&amp;gt; [X][Y] and (X)(Y)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Where X and Y are any set of terms. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Since a term can be reduced in two ways, there maybe
more that one solution for a given expression. A valid solution cannot have a contradiction.
Here are some example reductions – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a b c)[c d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a)[b c][c d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a)(b)(c)(d)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is another solution for the same –&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a b c)[c d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a)[b c][c d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a)[b][c][d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is another solution for the same –&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a b c)[c d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;[a](b c)[c d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;[a](b)[c][d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is another solution for the same –&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a b c)[c d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;[a](b c)[c d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;[a](b)[c][d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Independent
Variables:&lt;/b&gt; When reducing a term we select one variable and assign it both type
values. The values of other symbols/variables might be get fixed as a consequence
of this. Such variables are referred to as independent variables. In the general case,
the maximum number of solutions than an expression can generate is 2^n where n is
the number of independent variables. Since one or both choices of type assignment
may result in a contradiction the number of actual solutions maybe lesser than this. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In the above example, there were two independent variables
a and b. c and d values were fixed by the selection of values for a and b. Hence there
were 4 solutions. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Ex:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a b)(b c)(c a)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a)[b](c)[a] &amp;lt;-- contradiction&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;[a](b)[c](a) &amp;lt;-- contradiction 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This expression has no solutions.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a b)(a c)(a d)[b c d]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;(a)[b][c][d] &amp;lt;-- this
is one solution&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;[a](b)(c)(d) &amp;lt;-- this
is a contradiction. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The above expression has only one solution&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;End. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;That’s it. That’s all I know about this thing. I would
like to create a method to predict how many solutions an expression may have. I don’t
know how to do that. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I also would like to explore extensions to the algebra
in terms of adding more types to the algebra. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Adding
More Types&lt;/b&gt;: Right now I have only two types () and []. One can think of the relation
between these as that of the relation between –ve and +ve, or as odd and even. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;()()
= [] &lt;/span&gt;&lt;/b&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;or&lt;/span&gt;&lt;/i&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt; odd
odd = even &lt;/span&gt;&lt;/b&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;or&lt;/span&gt;&lt;/i&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt; -
- = +&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt;()[]
= () &lt;/span&gt;&lt;/b&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;or&lt;/span&gt;&lt;/i&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt; odd
even = odd &lt;/span&gt;&lt;/b&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;or&lt;/span&gt;&lt;/i&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="COLOR: navy"&gt; -
+ = -&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One can consider adding three types (), [] and {} such
that &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;() = []{} and {}[]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;[] = (){} and {}()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;{} = []() and ()[]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I don’t know what sorts of types map to. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One can consider +, -, +i and –i as four types as well
and so on. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;What
is this useful for?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I was working on solving another problem and the search
space for that was too large. I was looking for a way of reducing the search space
and for compactly representing this search operation when I realized that I could
express the problem like this. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The original problem was that I had a matrix like the
one below. I could assign and + or negative sign to any variable such that the matrix
when multiplied by its transpose would generate the identity matrix. (The transpose
of a matrix is the matrix you get when you flip it along its diagonal). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;a b c d&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;b a d c&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;c d a b&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;d c b a&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Then I had to solve the problem for the larger 8x8
version of the same matrix – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;a b c d e f g h&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;b a d c f e h g&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;c d a b g h e f&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;d c b a h g f e&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;e f g h a b c d&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;f e h g b a d c&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;g h e f c d a b&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;h g f e d c b a&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;These matrices are generated as a consequence of simple
XOR order, that can be easily expressed by the following ruby program – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;syms = %w(a b c d e f g h i
j k l m n o p q r s t)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;v = 8&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;v.times{|m|&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;v.times{|n|&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;printf("%s
", syms[n^m])&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;puts
""&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The fact is that I had to solve the problem for matrices
of any dimension that is a power of two and I couldn’t see any pattern that would
help me automagically generate the signs for matrices of higher dimensions. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So I though about how to search the space of all possible
sign assignment and then realised that I can group elements into groups of four such
that each group would have 4 variables and would be of type (). As an example here
is the expression in FooGroup algebra which when solved would give all the solutions
possible.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(r1c0,r1c1,r0c0,r0c1)(r1c2,r1c3,r0c2,r0c3)(r2c0,r2c2,r0c0,r0c2)(r2c1,r2c3,r0c1,r0c3)(r2c0,r2c3,r1c0,r1c3)(r2c1,r2c2,r1c1,r1c2)(r3c0,r3c3,r0c0,r0c3)(r3c1,r3c2,r0c1,r0c2)(r3c0,r3c2,r1c0,r1c2)(r3c1,r3c3,r1c1,r1c3)(r3c0,r3c1,r2c0,r2c1)(r3c2,r3c3,r2c2,r2c3)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Where r0c1 is the symbol for the sign that should be
given to element at row 0 column 1. (I further go on to fix my first row to be all
positive numbers. )&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Finally, if you are interested I have a .Net library
to solve expressions in the algebra. I also have a ruby program that generates C#
programs which get the library to solve the above matrix problem. &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;The
build command takes as parameter the dimensions of the matrix that you wish to solve
(this should be a power of 2). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;a href="/pensieve/content/binary/foo-group-algebra.zip"&gt;Download
FooGroup Algebra and the Matrix Solver&lt;/a&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Running the solver on a 4x4 matrix generates 16 solutions.
2048 solutions for a 8x8 matrix. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solving
:(r1c0 r1c1)(r1c2 r1c3)(r2c0 r2c2)(r2c1 r2c3)(r1c0 r1c3 r2c0 r2c3)(r1c1 r1c2 r2c1
r2c2)(r3c0 r3c3)(r3c1 r3c2)(r1c0 r1c2 r3c0 r3c2)(r1c1 r1c3 r3c1 r3c3)(r2c0 r2c1 r3c0
r3c1)(r2c2 r2c3 r3c2 r3c3)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
1 : (r1c1)(r1c3)(r2c2)(r2c1)[r2c3](r2c1)(r3c3)[r3c1](r3c2)[r3c1][r3c1](r3c2)[r1c0][r1c2][r2c0][r3c0]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
2 : (r1c1)(r1c3)(r2c2)(r2c1)[r2c3](r2c1)[r3c3](r3c1)[r3c2](r3c1)(r3c1)[r3c2][r1c0][r1c2][r2c0](r3c0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
3 : (r1c1)(r1c3)[r2c2][r2c1](r2c3)[r2c1](r3c3)[r3c1](r3c2)[r3c1][r3c1](r3c2)[r1c0][r1c2](r2c0)[r3c0]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
4 : (r1c1)(r1c3)[r2c2][r2c1](r2c3)[r2c1][r3c3](r3c1)[r3c2](r3c1)(r3c1)[r3c2][r1c0][r1c2](r2c0)(r3c0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
5 : (r1c1)[r1c3](r2c2)[r2c1](r2c3)[r2c1](r3c3)(r3c1)[r3c2](r3c1)(r3c1)[r3c2][r1c0](r1c2)[r2c0][r3c0]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
6 : (r1c1)[r1c3](r2c2)[r2c1](r2c3)[r2c1][r3c3][r3c1](r3c2)[r3c1][r3c1](r3c2)[r1c0](r1c2)[r2c0](r3c0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
7 : (r1c1)[r1c3][r2c2](r2c1)[r2c3](r2c1)(r3c3)(r3c1)[r3c2](r3c1)(r3c1)[r3c2][r1c0](r1c2)(r2c0)[r3c0]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
8 : (r1c1)[r1c3][r2c2](r2c1)[r2c3](r2c1)[r3c3][r3c1](r3c2)[r3c1][r3c1](r3c2)[r1c0](r1c2)(r2c0)(r3c0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
9 : [r1c1](r1c3)(r2c2)[r2c1](r2c3)[r2c1](r3c3)(r3c1)[r3c2](r3c1)(r3c1)[r3c2](r1c0)[r1c2][r2c0][r3c0]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
10 : [r1c1](r1c3)(r2c2)[r2c1](r2c3)[r2c1][r3c3][r3c1](r3c2)[r3c1][r3c1](r3c2)(r1c0)[r1c2][r2c0](r3c0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
11 : [r1c1](r1c3)[r2c2](r2c1)[r2c3](r2c1)(r3c3)(r3c1)[r3c2](r3c1)(r3c1)[r3c2](r1c0)[r1c2](r2c0)[r3c0]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
12 : [r1c1](r1c3)[r2c2](r2c1)[r2c3](r2c1)[r3c3][r3c1](r3c2)[r3c1][r3c1](r3c2)(r1c0)[r1c2](r2c0)(r3c0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
13 : [r1c1][r1c3](r2c2)(r2c1)[r2c3](r2c1)(r3c3)[r3c1](r3c2)[r3c1][r3c1](r3c2)(r1c0)(r1c2)[r2c0][r3c0]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
14 : [r1c1][r1c3](r2c2)(r2c1)[r2c3](r2c1)[r3c3](r3c1)[r3c2](r3c1)(r3c1)[r3c2](r1c0)(r1c2)[r2c0](r3c0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
15 : [r1c1][r1c3][r2c2][r2c1](r2c3)[r2c1](r3c3)[r3c1](r3c2)[r3c1][r3c1](r3c2)(r1c0)(r1c2)(r2c0)[r3c0]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solution
16 : [r1c1][r1c3][r2c2][r2c1](r2c3)[r2c1][r3c3](r3c1)[r3c2](r3c1)(r3c1)[r3c2](r1c0)(r1c2)(r2c0)(r3c0)&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=3abd9d48-cec9-478b-bccf-3072f2c3dd42" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,3abd9d48-cec9-478b-bccf-3072f2c3dd42.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=65223f21-a4f5-4eea-8d17-6c191cc48a02</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,65223f21-a4f5-4eea-8d17-6c191cc48a02.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,65223f21-a4f5-4eea-8d17-6c191cc48a02.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=65223f21-a4f5-4eea-8d17-6c191cc48a02</wfw:commentRss>
      <slash:comments>6</slash:comments>
      <title>Yield for Scheme</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,65223f21-a4f5-4eea-8d17-6c191cc48a02.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/10/24/YieldForScheme.aspx</link>
      <pubDate>Mon, 24 Oct 2005 22:40:28 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;This
article is relevant in the context of 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,21892608-a48c-414b-930f-d0ddecbc5b07.aspx"&gt;&lt;font face=Arial&gt;Search
for Yield the Magnificent&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,e8703ac2-34ab-43b9-bbc7-35498824a354.aspx"&gt;&lt;font face=Arial&gt;Yielding
to Magnificence&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Other
relevant articles include:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://blogs.applibase.net/sidharth/?p=31"&gt;&lt;font face=Arial&gt;Iterators that
listen (for Python, by Sidharth Kuruvila)&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://blogs.applibase.net/sidharth/?p=32"&gt;&lt;font face=Arial&gt;Implementing
a generator in Ruby (by Sidharth Kuruvila)&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,fd10bfa8-1aeb-4353-84c8-cd80e418424f.aspx"&gt;&lt;font face=Arial&gt;Implementation
of Iterators in C# 2.0&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I finally
got down to ironing out the issues in the previous (rather hasty) entry about scheme
iterators. I have code that is a little better tested. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;To sell
any idea, you have to demonstrate the value that believers in the idea get, before
you discuss the cost. So here is the value –&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Iterators support a style of programming where you
separate producers of streams of data from consumers of these streams. For example
you want to do a certain something on strings of text, irrespective of where the text
comes from. In a more general case, iterators are a more powerful programming device,
they can be thought of call-tree walkers, they can be thought of the notion of structured
programming as applied to continuations. (Refer: &lt;/font&gt;&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,02da61dd-1e35-4a36-b46b-aa3a605b2ad6.aspx"&gt;&lt;font face=Arial&gt;Warming
up to Iterators,&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; &lt;/font&gt;&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,02da61dd-1e35-4a36-b46b-aa3a605b2ad6.aspx"&gt;&lt;font face=Arial&gt;Ruby:
Containers, Blocks and Iterators&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;, &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/04/05/C20/"&gt;&lt;font face=Arial&gt;C#:
Create Elegant Code with Anonymous Methods, Iterators, and Partial Classes&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The following is a demonstration of yield (similar
to yield in Ruby, C# or Py) as a device to create iterators in scheme. There are some
extensions to the idea, so the yield implementation here can do more things than the
any of the other implementations can do (refer &lt;/font&gt;&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,21892608-a48c-414b-930f-d0ddecbc5b07.aspx"&gt;&lt;font face=Arial&gt;here
for details&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;). The implementation below is
however useful in a functional context (its easy to see the use of yield in a imperative
context). All of the code snippets below are functional in nature, the actual implementation
of iterators need not be, but these internal details are abstracted away from you. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;lambda-iter,
yield, foreach&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Iterators (functions that use yield) are defined using
lambda-iter&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(define even&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda-iter
()&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
loop ((i 0))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(printf
"even recieved ~a ~n" (yield i))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(loop
(+ i 2)))))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;; Using foreach&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(foreach (even) &lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(printf
"it = ~a ~n" it) ; ‘it’ is the yielded value&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(&amp;gt; it 20) &lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(break
0)) ;break out if we has enough&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;strong&gt;&lt;font color=#008000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;it)
;return the yielded value to yield&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The even above is an produces an infinite stream of
even numbers. The parameter to break is the return value of the foreach. ‘it’ is the
value of the value that has been yielded. This common to many languages (Groovy, COmega
etc). Everything else should be easy to understand. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;coroutine,
co-move-next, co-value, co-return, co-finished?, co-not-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Iterators can be turned into first class entities as
follows –&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;; Using coroutines explicitely&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;; Here the control flow mechanism is
something we control&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(let loop ((co (coroutine (even))))
;create the corotuine object&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(let
((co (co-move-next co))) ; start/advance the execution&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(printf
"Yielded ~a ~n" (co-value co)) ; print the yielded value&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;strong&gt;&lt;font color=#008000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(loop
(co-return (co-value co) co)))) ;return the yielded value&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;There, that’s said, you have all the devices that you
need for a yield the magnificent implementation for scheme. There are more things
in this implementation to make it useful for general purpose programming, but this
much covers all the intellectual content. What follows is some essential documentation
after which we have some of the extra forms. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Documentation&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;lambda-iter&lt;/i&gt;&lt;/b&gt; &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(lambda-iter
&amp;lt;params&amp;gt; &amp;lt;body&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Same as lambda, except that you can do a &lt;b style="mso-bidi-font-weight: normal"&gt;yield&lt;/b&gt; in
its body&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;yield&lt;/i&gt;&lt;/b&gt; &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(yield
&amp;lt;value&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Yields a value to the caller&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;foreach&lt;/i&gt;&lt;/b&gt; &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(foreach
&amp;lt;iterator&amp;gt; &amp;lt;body&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Takes an iterator and list of expressions, the expressions
are invoked everytime the iterator yields. The value yielded is available as ‘&lt;b style="mso-bidi-font-weight: normal"&gt;it&lt;/b&gt;’.
The expression can abort from the foreach by calling &lt;b style="mso-bidi-font-weight: normal"&gt;break&lt;/b&gt;.
The parameter to break is the return value of the foreach. If the iterator returns,
before break is called, the foreach returns the value of the iterator. Tha value of
the last evaluated expression in the expression list is the return value into the
iterator. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;coroutine – wraps the iterators into a coroutine object&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;coroutine&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(coroutine
&amp;lt;iterator&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Wraps the iterator into a first class object and returns
it.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-move-next&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(co-move-next
&amp;lt;coroutine&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Executes the iterator in the coroutine, till it yields
or till it returns. The new coroutine is returned. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-value&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(co-value
&amp;lt;coroutine&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Retrieves the current value of the coroutine. This
might be a yielded value or a return value of the iterator.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Functional
programmers may want to use the analogy of car and cdr for co-value and co-move-next.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-return&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(co-return
&amp;lt;value&amp;gt; &amp;lt;coroutine&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;Sets a return value into the coroutine and returns
the new coroutine object. The return value is the value that will be avilavle as the
return value of a yield call inside the iterators. Example (let ((a (yield 10)) …
) here the value of a will be the value that was set using a co-return in the coroutine
object.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-finished?,
co-not-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(co-finished?
&amp;lt;coroutine&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Returns a bool to indicate if the coroutine has returned.
If it has yielded and can potentially do something meaningful for subsequent co-move-next
calls, co-finished will return #f. co-not-finished is the complement. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Recursive
yields&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;;; recursive yielding&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;; yields all combinations of true and
false for n bits&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(define states&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda-iter
(n)&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(eq? n 1) &lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(begin &lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(yield
'(#f)) (yield '(#t)))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(foreach
(states (- n 1))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;(yield
(cons #f it))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(yield
(cons #t it))))))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(foreach (states 5)&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;strong&gt;&lt;font color=#008000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(printf
"state = ~a ~n" it))&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is an example of recursive yielding. The states
function returns all the values of a bit vector of size ‘n’ bits.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;yield-all&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;yield all is a useful pattern sometimes when you recursively
call iterators. Here is a tree walker that is implemented using yield-all and yield.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(define walk-tree&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda-iter
(tree)&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cond&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((null?
tree) '())&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;((atom?
tree) &lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(yield
tree))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(else&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(yield-all
(walk-tree (car tree)))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(yield-all
(walk-tree (cdr tree)))))))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(foreach (walk-tree '(1 2 3 (5 6 7)
(4 5) 8))&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;strong&gt;&lt;font color=#008000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(printf
"value ~a~n" it))&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;There is an intuitive way to think about these sort
of programs – each node is a tree yields itself if it is a a leaf (an atom). Else
it asks each of its children to &lt;i style="mso-bidi-font-style: normal"&gt;yield-all&lt;/i&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solving
the Same-Fringe problem&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The same fringe problem is the problem of comparing
two trees to see if they have the same leaf values, irrespective of the structure
of the trees. One way of solving the same fringe problem is to use the walk-tree defined
above and create two couroutines, to represent the two trees that are to be compared. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(define same-fringe&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(t1 t2)&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
loop ((t1 (coroutine (walk-tree t1))) &lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(t2
(coroutine (walk-tree t2))))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
((t1 (co-move-next t1)) (t2 (co-move-next t2)))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(and (co-finished? t1) (co-finished? t2))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;#t&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(or (co-finished? t1) (co-finished? t2))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;#f&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(eq? (co-value t1) (co-value t2))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(loop
t1 t2)&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;strong&gt;&lt;font color=#008000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;#f)))))))&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;The intuitive way of looking at this is that
it created two coroutines and advances both of them. If they both finish, then the
trees have same fringe. If only one of them have terminated then the trees are not
equal with respect to fringe values. If neither of them have terminated and the values
they yielded are the same, then we can loop and ask for the next value. &lt;i style="mso-bidi-font-style: normal"&gt;As
an aside, I find the code above to be far more readable that the equivalent in the
Dorai Sitaram text. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/i&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;coroutines,
co-all-move-next, co-all-finished?, co-any-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is a solution to the same fringe using some handy
helper routines that help with dealing with collections of coroutines. These functions
are usually useful only when all the coroutines are similar or related in some way.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(define same-fringe2&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(t1 t2)&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
loop ((ts (coroutines (walk-tree t1) (walk-tree t2))))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
((ts (co-all-move-next ts)))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cond &lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((co-all-finished?
ts) #t)&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((co-any-finished?
ts) #f)&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((eq?
(co-value (car ts)) (co-value (cadr ts))) (loop ts))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;strong&gt;&lt;font color=#008000&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(else
#f))))))&lt;/font&gt;&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Solving
the repmin problem&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The repmin problem requires that you trake a tree and
construct a new tree where every leaf is replaced by the global minimum leaf value&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;of
the original tree. (This is the problem that started this saga off and was the one
that none of the C#, Ruby, Py yields could handle)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The solution below can repmin trees not only binary
trees, but trees of any arity. This shows of the flexibility of the some of the couroutine
list comprehension functions&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;that are
available – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;;a powerful repmin that works on trees with arbitrary
numbers of leaves&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(define repmin&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda-iter
(tr)&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cond&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((atom?
tr) (yield tr))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((null?
tr) '())&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(else&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let*
((co-trs (co-all-move-next (map coroutine (map repmin tr))))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(co-vals
(co-values co-trs)))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(co-values&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(co-all-move-next &lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#008000&gt;&lt;strong&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(co-all-return
(yield (apply min co-vals)) co-trs))))))))&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;;Test&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#008000&gt;&lt;strong&gt;(define tree1 '(3 ((2)) (3 4) 1))&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=StyleCodeSnippet8ptSeaGreen style="MARGIN: 0in 0in 0pt"&gt;
&lt;strong&gt;&lt;font face="Courier New" color=#008000&gt;(printf "Repmin of ~a is ~a ~n" tree1
(foreach (repmin tree1) it))&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Documenting
the extra forms&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;yield-all 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(yield-all
&amp;lt;iterator&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Equivalent of (foreach &amp;lt;iterator&amp;gt; (yield it))&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;coroutines&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(coroutines
&amp;lt;iterator&amp;gt;+)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Create a list of coroutines. Equivalent of (map coroutine
&amp;lt;iterator list&amp;gt;)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-all-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-none-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-any-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(co-all-finished
&amp;lt;coroutine list&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-values&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(co-values
&amp;lt;coroutine list&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Returns a list of values, which are the value sof each
of the coroutines&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-all-move-next&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(co-all-move-next
&amp;lt;coroutine list&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Moves all the coroutines in the list to the next value
and returns the new list of coroutines.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-all-return&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(co-all-return
&amp;lt;value&amp;gt; &amp;lt;coroutine list&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Applies a return value to all of the coroutines and
returns the new list of coroutines. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;co-each-return&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(co-each-return
&amp;lt;values list&amp;gt; &amp;lt;coroutine list&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Applies a return value from the values list to each
of the coroutines and returns the new list of coroutines. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Implementation 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is the implementation of coroutine, yield and
all the support stuff…&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;Roshan
James (Mon 10/24/2005)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;call/cc
based implementation of Yield the Magnificient for Scheme&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;Yield
the Magnificient:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;http://www.thinkingms.com/pensieve/default,date,2005-10-11.aspx&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;A
coroutine is represented by a list of 3 values. The first of these is a 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;proc(1),
the second is a value(2), the third is a bool(3). According to 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;different
stages in the lifetime of a coroutine, these have different values. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;
Values of proc(1)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;1)
When a corotuine is created the proc is the 'first lambda'&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;2)
When the iterator is running, the proc is the continuation of the iterator&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;3)
When the iterator has returned, the proc is the null-proc.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;Values
of value(2)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;1)
When the coroutine is created, it is simply #t&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;2)
When the iterator is running, it is the current yielded value&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;3)
When the iterator has returned, it is the final return value&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;Values
of bool(3)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;
The bool of #f after the iterator has returned. Until then the bool is #t.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;Coroutines
can be sent return values, by replacing value(2) in the list&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;before
calling co-move-next. Once a coroutine has terminated, co-move-next can be 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;called
an infinite number of times without having any effect. The return&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;value
is preserved (all these calls are sent to null-proc).&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
coroutine&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(prod)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(list
(lambda (ret) ;first lambda&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(letrec
((esc (car ret)) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(null-proc
(lambda (x) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cons
null-proc (cdr x)))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
((stopped (list null-proc&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(prod
(lambda (it)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;(let
((res (call-with-current-continuation 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(k)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(esc
(list k it #t)))))) ; iterator k&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(set!
esc (car res)) ;Evil!&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cadr
res))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;#f)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(esc
stopped))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;#t
#t)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-move-next&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(co)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(call-with-current-continuation 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;(lambda
(esc)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((car
co) (list esc (cadr co) (caddr co)))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;There
is no intellectual content past this point, the rest of the code is required&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;to
provide abstractions that I thought are are useful from my experince with using&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;yield.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-value&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(co) (cadr co)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(co) (not (caddr co))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-not-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(co) (caddr co)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-return&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(val co) (list (car co) val (caddr co))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;Some
useful macros&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;create
a producer that has a implicit curried yield&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define-syntax
lambda-iter&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(f)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(syntax-case
f ()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[(_
(x* ...) body body* ...)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(with-syntax
([yield-syntax (datum-&amp;gt;syntax-object (syntax _) 'yield)])&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(syntax&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(x* ...)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(yield-syntax)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;body&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;body*
...))))])))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;can
be called in an iterator to yield all the values yielded&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;by
an iterator it is calling&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define-syntax
yield-all&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(f)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(syntax-case
f ()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[(_
iter)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(with-syntax
([yield-syntax (datum-&amp;gt;syntax-object (syntax _) 'yield)])&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(syntax&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(iter
(lambda (it) (yield-syntax it)))))])))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;a
foreach that mostly useful only in an imperative context&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define-syntax
foreach&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(f)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(syntax-case
f ()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[(_
iter body* ...)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(with-syntax
([it-syntax (datum-&amp;gt;syntax-object (syntax _) 'it)]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[break-syntax
(datum-&amp;gt;syntax-object (syntax _) 'break)])&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(syntax&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(call-with-current-continuation&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(break-syntax)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(break-syntax
(iter 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(it-syntax) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;body*
...)))))))])))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;reduce&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
reduce&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(proc ls)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cond&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((null?
(cddr ls)) (proc (car ls) (cadr ls)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(else&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(proc
(car ls) (reduce proc (cdr ls)))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;;useful
functions for dealing with lists of iterators&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
coroutines 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
ls&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(map
coroutine ls)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-all-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(ls)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;(reduce
(lambda (a b) (and a b))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(map
(lambda (iter) (co-finished? iter)) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ls))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-any-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(ls)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(reduce
(lambda (a b) (or a b))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(map
(lambda (iter) (co-finished? iter)) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;ls))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-none-finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(ls)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(reduce
(lambda (a b) (and a b))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(map
(lambda (iter) (co-not-finished? iter)) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ls))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-values&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(ls)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(map
co-value ls)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-all-move-next&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(ls)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(map
co-move-next ls)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(define
co-all-return&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(ret ls)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(map
(lambda (iter) (co-return ret iter)) ls)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: navy; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/content/binary/scheme_yield.zip"&gt;&lt;font face=Arial&gt;Here
are the files for download.&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;What
is the value of all of this?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The value of all of this would be to look at the above
as a general way of implementing yield in languages where the approach is to pass
a closure from the caller to the callee. Ruby is another language in this category
and I believe the Generator class was an attempt to solve this problem. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The real value in all of this is in setting a base
for further exploration of the style of programming that yield lends itself to. Is
it sufficiently expressive to express all implementation of certain classes of problems?
If so, then yield maybe useful as a primitive building block for large classes of
control structures in programming languages. If not, all of this was fun anyway. :)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/content/binary/scheme_yield.zip"&gt;&lt;font face=Arial&gt;Download&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=65223f21-a4f5-4eea-8d17-6c191cc48a02" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,65223f21-a4f5-4eea-8d17-6c191cc48a02.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=e8703ac2-34ab-43b9-bbc7-35498824a354</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,e8703ac2-34ab-43b9-bbc7-35498824a354.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,e8703ac2-34ab-43b9-bbc7-35498824a354.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=e8703ac2-34ab-43b9-bbc7-35498824a354</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <title>Yielding to Magnificence</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,e8703ac2-34ab-43b9-bbc7-35498824a354.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/10/16/YieldingToMagnificence.aspx</link>
      <pubDate>Sun, 16 Oct 2005 02:39:12 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;Python&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Firstly, halfway across the planet, Sid created what
could be for most part Yield the Magnificent for Python. (I am not fully convinced
that he hasn’t lost property 6, but he has fixed 3 and 5.) But that should not come
as much of a surprise to me because I have met few Py programmers like Sid :) Here
is Sid’s &lt;/font&gt;&lt;a href="http://blogs.applibase.net/sidharth/?p=31"&gt;&lt;font face=Arial&gt;Iterators
that Listen&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Scheme&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is something that I have for scheme. It needs
to have details ironed out. But effectively this does a coroutining “transform” of
the caller. This puts it in the same category of ‘solution’ as ruby’s ‘generator’
class. This is also the operational equivalent of what py and c# have done. In the
scheme world resume state is maintained by a continuation. In the Py or C# world,
state is maintained by creating an object. For the scheme solution below, the basic
ideas came from the brain storming session with William Byrd and Matt Ellis on this
Friday. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is the scheme code:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;(define
coroutine&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(prod)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(list
(lambda (ret)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
((esc (car ret)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(list
(lambda (x) x)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(prod
(lambda (it)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
((res (call-with-current-continuation 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(k)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(esc
(list k it #t))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(set!
esc (car res)) ;Evil!&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cadr
res))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;#f)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;#t
#t)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;(define
move-next&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(co)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(call-with-current-continuation 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(esc)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((car
co) (list esc (cadr co) (caddr co)))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;(define
valueof?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(co) (cadr co)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;(define
finished?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(co) (caddr co)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;(define
set-return&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(co val) (list (car co) val (caddr co))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Writing
a Producer / Generator / Iterator 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One this is in place one can write an iterator that
looks like so – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal; mso-bidi-font-size: 12.0pt"&gt;(define
even&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(yield)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
loop ((i 0))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(display
(yield i))(newline)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(loop
(+ i 2))))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It is conceivable that we can have a macro to hide
the currying of the inner lambda (yield). However it is easy to see that One can write
producers that assume that they have a yield keyword handy.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Writing
the consumer&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;To use the use the iterator as a first class object,
you simply do – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal; mso-bidi-font-size: 12.0pt"&gt;(let
loop ((co (coroutine (even))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(let
((co (move-next co)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(display
"Yielded ")(display (valueof? co))(newline)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: #993300; FONT-FAMILY: 'Courier New'; mso-bidi-font-family: Mangal; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(loop
co)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Consumer code like the above is free from any forced
invocation by the producer and hence does not need a ‘break’. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Functional
programming&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The co objects are first class and can be passed around
– they are not bound to any syntactic structure. Hence having a yield facility is
now meaningful in a functional context (which was one of Will Byrd’s concerns). The
implementation of the coroutine is itself is not functional. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Lockstep
iteration / &lt;i style="mso-bidi-font-style: normal"&gt;apply-iterator&lt;/i&gt; / Iterator composition&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It is conceivable that when you have a one one producer
you might want a syntactic structure that also gives you a break. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;However I don’t think its meaningful to create a general
purpose apply-iterator. The reason is simple: Iterators are blocks of code that can
yield a arbitrary number of values. If you decide to lockstep with each iterator producing
a different number of yields, when should the composition of these iterators stop?
There would be problems that need all of them can halt when the first one halts. There
would be others where you might want the last iterator to stop before the the whole
structure stops. So at the least you need at least &lt;i style="mso-bidi-font-style: normal"&gt;‘and’&lt;/i&gt; and &lt;i style="mso-bidi-font-style: normal"&gt;‘or’&lt;/i&gt; semantics
between the finished cases. There might be algorithms where you need other behaviors.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Instead of defining these syntactic structures and
defining rules for composition it is sufficient to convert individual iterators into
coroutines. You can see that it would be very handy to have some nice list comprehensions
to make it easy to use several coroutines in combination. As a matter of fact, all
sorts of useful macros could be devised. However, there maybe no useful apply-iterator
operator. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Now who
can fix my imperative favorites, C# and Ruby?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=e8703ac2-34ab-43b9-bbc7-35498824a354" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,e8703ac2-34ab-43b9-bbc7-35498824a354.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=566a06d8-5278-4658-9077-29920b5a99a6</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,566a06d8-5278-4658-9077-29920b5a99a6.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,566a06d8-5278-4658-9077-29920b5a99a6.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=566a06d8-5278-4658-9077-29920b5a99a6</wfw:commentRss>
      <title>Judas to the Temple of Lambda</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,566a06d8-5278-4658-9077-29920b5a99a6.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/10/13/JudasToTheTempleOfLambda.aspx</link>
      <pubDate>Thu, 13 Oct 2005 02:37:40 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Last night I was writing some for OS161 – I was implementing
a fork(), execv(), getpid(), waitpid() and exit() for the OS161 kernel. I was using
Visual Studio Express VC++ edition beta2 to write the code and I had a little ruby
script to upload changed file to my linux (gasp!) box and a little script there that
would build the kernel whenever the files changed. That way I get to develop code
on an OS that has a notion of a unified clipboard and such pleasantries and get to
build it wherever the tools are available. I also got a minimal shell like first process
done.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Don’t get me wrong when I say this, but I sometimes
like to think of myself as a fairly decent imperative programmer – I would be comparably
good to many people you might meet. Ever since I came to college functional programming
has been rewiring my brain. And its beginning to hurt. And I am enjoying it. And sometimes
you need a break.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Hence writing missing pieces in a simplistic os kernel
is a nice break. And I am going “Ooh! Look I have variables! Ooh! Look I can reassign
the value of this thing. Look, I have loops”. And that’s a nice world to be in, if
you can think in terms of state well – for those of you imperative programmers don’t
know what that is, it means that things have changable values (like x=5 and x ++;)
– and those of you who don’t realize you are imperative programmers, here is a simple
test: if you are not a Haskell (and similar) programmer Or Scheme programmer (without
set!) Or mathematician Or someone who goes from day to day without anything in the
world affecting you, you are a imperative programmer of some device. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So I was enjoying being imperative for a while and
then when I had it all going halfway into the night – I had multiple processes forking
and execing and waitpiding and exiting – the whole crashes. And then it crashed again.
And this was crazy, because all the of the pieces were things I had tested separately
and yet they crashed when they came together. Somewhere in the back of my head there
was this &lt;/font&gt;&lt;a href="http://www.cs.indiana.edu/~prohwer/lg_littleschemer.jpg"&gt;&lt;font face=Arial&gt;little
elephant called lambda laughing on the floor ignoring his cons-kit for a bit.&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; But
wait a minute, I thought all this functional programming was making me a better programmer
– I thought I could think more clearly about composition. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;After about 2hours of meditation and atleast one or
two sets of forays into the debugger as a last recourse, I realized what the problem
was that I was not writing things back onto the user space stack in the correct alignment
in some cases – and the this was some dword alignment requirement of this machine
that was not mentioned anywhere. Lambda and the &lt;a href="http://www.muppetlabs.com/~breadbox/bf/"&gt;Turing
tape&lt;/a&gt; looked down, looking a little sorry. I was in a bad mood by the end of it
and that wasn’t fair – that was my little imperative break.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;All of this, gets me to some of the conversations with
some of my professors here. Dan Friedman is one of the kindest gentlest people you
can talk to – and pretty much every other sentence some brain mutilating idea, said
in the kindest subtlest way possible. So it happened that I needed to prove that something
is not possible (it is related to the &lt;/font&gt;&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,21892608-a48c-414b-930f-d0ddecbc5b07.aspx"&gt;&lt;font face=Arial&gt;hypothetical
apply-iterator operator I speak of here&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;).
Fifiteen minutes after the conversation I am thinking about higher order programming
with continuations and my brain is hurting. (do you know what that means? If you don’t
you need to go though the experience of hitting upon an idea that changes the way
you look at the world. Changes the way you look at the world does not mean that the
next time you eat a burger you look at it slightly more from the left, it is a little
more encompassing an idea.) &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;An idea
isn’t responsible for the people who believe in it. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Programming languages are devices to express thought.
The fact that you can also create software using them are only secondary to this larger
idea. Languages carry ideas of meaning and operation and you can compose these things
together to create larger meanings and wider operations, or compose them to narrow
down their scope. If you are a starting C programmer or an accomplished C# or Java
programmer, it maybe hard to see things this way – but that is ok, you don’t always
have to know the full import of what you could be doing. (I will write about Haskell
and the wizard called Prof Amr Sabry some other time.)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One of the hardest things or like Prof Friedman says
it is probably the simplest of all things is the idea of a continuation. It is an
idea so simple that it drives you crazy trying to understand it. Imagine that if you
did something, anything, it has rippling effects across the rest of all time – now
imagine that you can take this ‘rest of all time’ and assign it to a variable and
pass it around through all the operations you do, such that at some time you can go
back to that rest of the world. That is a continuation. That as a programming device
is good way to inflict some brain damage if you try to internalize it. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;That’s
about when I thought I should quit. That I probably should not go functional. All
of this was too hard – you start out with something because you feel that there is
some beauty and some truth in it. And when that fails you, maybe its time to betray
you way of thinking – maybe its time to quit. By this point, you realize, that I might
be quiet crazy, and that it might be rubbing off on you since you are still reading
this. Betray the 
&lt;st1:place w:st="on"&gt;
&lt;st1:PlaceType w:st="on"&gt;temple&lt;/st1:PlaceType&gt;
of 
&lt;st1:PlaceName w:st="on"&gt;Lambda&lt;/st1:PlaceName&gt;
&lt;/st1:place&gt;
?&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;That’s when Judas’s song from Jesus Christ Super Star
(which I have been listening to a lot these days) plays in the back of my mind, when
he does to Caiphus to betray Christ - &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Now if
I help you, it matters that you see 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;These
sordid kinda things are coming hard to me. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;It's taken
me some time to work out what to do&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I weighed
the whole thing out before I came to you. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I have
no thought at all about my own reward. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I really
didn't come here of my own accord. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Just don't
say I'm ... damned for all time.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I came
because I had to; I'm the one who saw. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Jesus
can't control it like he did before. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;And furthermore
I know that Jesus thinks so too. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Jesus
wouldn't mind that I was here with you. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I have
no thought at all about my own reward. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I really
didn't come here of my own accord. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Just don't
say I'm ... damned for all time&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;- Damned
for All time, Judas’s Song, JCSS.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;And then something snapped back in place and I was
at it again. Why have such a device as continuations? Why bother? Well we understand
little of continuations in my opinion. They are a thinking tool for the future. How
can something so mind bogglingly hard be useful? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A long time back I remember seeing a beginner book
about BASIC programming. That book had an example of the quicksort algorithm in basic
written using gotos. It was a only a few lines. I spent a whole evening trying to
understand what that was doing. And I didn’t succeed. I could execute the statements
in my mind and see how they work, but I could see how such a beast could be created.
I couldn’t see the way you would have to think to create something like that. Several
years later I saw &lt;/font&gt;&lt;a href="http://www.df.lth.se/~john_e/small/copper/copper.html"&gt;&lt;font face=Arial&gt;copper
bars by Tylisha C Anderson&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; and it was the
same death by gotos. I could not understand it. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Many years ago they got together and killed off gotos
and created a new-kid-on-the-block called structured programming. They took gotos
and created a set of patterns that are sufficiently expressive to do anything that
you could do using gotos. And then they killed off goto. The offspring forms the basis
of almost all imperative programming today. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The real value of something powerful that we cannot
tame yet is in what you can derive out of it. That’s when you say, in the conventional
sense, that something is sufficiently mature – when people who don’t understand the
first thing about it can use it to solve their programs (that’s the sense in which
I sometimes say that windows is more mature than linux…). I think I should stop now.
As you can see, college has been fun so far.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;What then
to do about this Jesus-mania?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Now how
to we deal with a carpenter king?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Where
do we start with a man who is bigger 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Than John
was when John did his baptism thing?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;- This
Jesus must die, Song of the Priests, JCSS&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I dreamed
I met a Galilean; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;A most
amazing man. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;He had
that look you very rarely find: 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;The haunting,
hunted kind.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I asked
him to say what had happened, 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;How it
all began. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I asked
again, he never said a word. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;As if
he hadn't heard.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;-
Pilate’s Dream, JCSS&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=566a06d8-5278-4658-9077-29920b5a99a6" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,566a06d8-5278-4658-9077-29920b5a99a6.aspx</comments>
      <category>Ethos</category>
      <category>Languages</category>
      <category>Mish Mash</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=21892608-a48c-414b-930f-d0ddecbc5b07</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,21892608-a48c-414b-930f-d0ddecbc5b07.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,21892608-a48c-414b-930f-d0ddecbc5b07.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=21892608-a48c-414b-930f-d0ddecbc5b07</wfw:commentRss>
      <slash:comments>13</slash:comments>
      <title>Search for Yield the Magnificent</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,21892608-a48c-414b-930f-d0ddecbc5b07.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/10/11/SearchForYieldTheMagnificent.aspx</link>
      <pubDate>Tue, 11 Oct 2005 04:44:25 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;After
a long time, one missing piece in the yield (iterator) puzzle fell in place in my
head. It should have been obvious because it had been staring at me in the face for
a while now. I am not sure, but it seems to me at this moment, that some of this might
be of lasting importance beyond the scope of this blog entry. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Time warp
3 or 4 years back to when Sid and I were discussing ruby iterators and python list
comprehensions. Sid had this notion that there was something missing in the Python
implementation that made ruby iterators more powerful. We however could not place
it at that time and we let it be. And we missed it for years after that. I am going
to make some claims that some languages can and cant do certain things – I might be
wrong and I hope that I am – if I am do show me how and maybe we can take this forward. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face=Arial&gt;The most powerful yield (iterator) construct
that I can think of, needs all of these – 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="COLOR: maroon; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;1)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face=Arial&gt;the
parent function that takes arguments&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="COLOR: maroon; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;2)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face=Arial&gt;the
parent function yields values&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="COLOR: maroon; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;3)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face=Arial&gt;the
parent function can return a one or more values finally and terminate&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="COLOR: maroon; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;4)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face=Arial&gt;the
parameter block of the yield should be able to ‘break’&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="COLOR: maroon; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;5)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face=Arial&gt;the
yield should be able return values into the iterator&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="COLOR: maroon; mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;6)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="COLOR: maroon"&gt;&lt;font face=Arial&gt;it
should possible to iterate two or more iterators in an interleaved manner. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;1 and 2 are obvious. Almost all implementations of
yield do this.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;3 means that there is a notion of the function returning
a value as the exit case of the function (such that the function instance terminates
and that it will not produce any more values). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;4 means that you should be able to do this &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;x.each {|y| break } 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;5 means that you should be able to do this &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;def foo&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;n
= yield 5&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;puts
n&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;6 means that you should be able to do this &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993366"&gt;&lt;font face="Courier New"&gt;a = foo1()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993366"&gt;&lt;font face="Courier New"&gt;b = foo2()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993366"&gt;&lt;font face="Courier New"&gt;puts a.next() + b.next()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993366"&gt;&lt;font face="Courier New"&gt;puts b.next() + a.next()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now, here is the search for yield the magnificent –
I don’t a language that gives me a yield that can do all of the above &lt;i style="mso-bidi-font-style: normal"&gt;and
I am upset&lt;/i&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;C# and Python rely on transformation of iterator (the
callee) into an object that models the the state machine of iterator code. They use
the objects state to maintain the environment for their closure (their state machine
transformed iterator function). &lt;/font&gt;&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,fd10bfa8-1aeb-4353-84c8-cd80e418424f.aspx"&gt;&lt;font face=Arial&gt;Read
more about C# 2.0 iterator implementation here&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;.
The ruby way as I understand is that the callers block is passed to the callee as
a closure. Scheme does not intrinsically have a yield, but you make an equivalent
by passing a closure to a callee function. I am aware that there are other languages
that implement the yield – Comega and Groovy, Icon and CLU – I don’t much about these
(except that I believe that Cw is similar to C# in this regard), and so I wont discuss
them here. Ever since ruby popularized the construct, it has found its way into many
languages. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;All of these support 1 and 2 above. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;C# and Python support 4 and 6. They don’t support returning
values from the function and do not support sending values into the iterator. This
means that you cannot write code similar to the powerful inject and other similar
‘reduce’ like constructs. Here is what the inject (courtesy of smalltalk looks like)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;class Array&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;def
inject n 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;each
{ |v| n = yield n, v } 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
n 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;def sum ls&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;v
= ls.inject(0){|n, v| n + v }&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
v&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Inject is very powerful as it enables creating a large
number of reduce like behavior. Inject itself is only one example of many things you
can do if you can control the execution of iterator by passing it values from its
consumer. The argument in favor of the return is weaker, but it is sufficient to say
that it it important to separate a final value, from that of the last yielded value. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(I am
not sure that Py cannot return a final value. If I am correct it terminates iteration
of next() calls by throwing an exception. It don’t know if it captures a return value
in the function object)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Scheme iterators, the simplistic approach that I have
in mind is&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366"&gt;&lt;font face="Courier New"&gt;(define iterator&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(x cls)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cls
(+ 1 x)) ; yield 1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cls
(+ 2 x)))) ; yield 2&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366"&gt;&lt;font face="Courier New"&gt;(define caller&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(iterator
10 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(lambda
(n) ; this lambda is in the lexical scope of caller&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 4"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(display
n)))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Should be equivalent to &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;def iterator&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;x&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
x + 1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
x + 2&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;def caller&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;iterator
{|n|&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;puts
n 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The limitation in scheme is that you cannot do a ‘break’
the block of the caller. Atleast there is no easy way to do this without grabbing
a continuation at the point of the call of the call to ‘iterator’, and then invoking
the abortive continuation in the closure argument cls. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-tab-count: 2"&gt;&lt;font face=Arial color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If if it given that the abortive continuation is a
natural way to do this, it is not obvious about how two iterators can created to lockstep
iterate into a single block of code. I will discuss this further below. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So scheme can do 1, 2, 3 and 5. It can’t ‘break’ without
continuations and cannot interleave or lockstep iteration in any obvious way. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Ruby, by far comes out with a lot of the above – the
only thing it can’t do is 6, that you cant interleave iterations. The fact that you
cannot interleave or lockstep iterations means that there whole classes of problems
that you cannot solve. The simple case is the classical example of co-routines or
continuations, the problem of comparing leaves of two trees. To compare the leaves
of two trees the standard solution is write a routine that traverses the tree recursively
and yields leaf values out of the recursive structure. You can then write a simple
compare routine that initializes two instances of this procedure with two trees you
want to compare, and then it merely compares the yielded values. This is the solution
in Comega – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;//the
int* represents a stream of 0 or more ints. It is not a int pointer. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;static
int* getleaves(node n)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(n
!= null)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(n.value
!= null)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
return n.value;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(
n.left != null) yield return getleaves( n.left );&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(
n.right != null) yield return getleaves( n.right );&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;static
bool samefringe(node tree1, node tree2)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;en1
= getleaves(tree1).GetEnumerator();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;en2
= getleaves(tree2).GetEnumerator();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;t1
= en1.MoveNext();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;t2
= en2.MoveNext();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//this
is the lockstep iteration&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;for(;
t1 &amp;amp;&amp;amp; t2; t1 = en1.MoveNext(),&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;t2
= en2.MoveNext())&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(
en1.Current != en2.Current ) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
false;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
!t1 &amp;amp;&amp;amp; !t2;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: #993366; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;As you can see, the class of problems that fall into
the above category is fairly large and its annoying that they cant be solved in ruby. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Note: Ruby provides something called a &lt;/font&gt;&lt;a href="http://www.ruby-doc.org/stdlib/libdoc/generator/rdoc/classes/Generator.html"&gt;&lt;font face=Arial&gt;generator&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; to
solve the problem of lockstep iteration. I like the language they describe this in
– &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Generator
converts an internal iterator (i.e. an Enumerable object) to an external iterator. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Note that
it is not very fast since it is implemented using continuations, which are currently
slow.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The first problem is that it grabs continuations over
something that already manages state. Lets assume that that’s transparent to us and
is a non-issue, there is a larger problem that generator created iterators violate
some of the other requirements, specifically 5: how you can send values into the iterator.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;g = Generator.new { |g|&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;n
= "hello"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;loop
{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;n
= g.yield( n )&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;puts
n&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;break
if n == nil&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;g.each {|n|&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;puts
n&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;n
+ "."&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;} 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font face=Arial color=#000000&gt;This code does
not work as expected (does not generate hellohello.hello..hello…). If there is something
amiss above that you can point out, let me know. &lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;All of this brings us closer to the conclusion – you
will notice that there are two approaches to the implementation of iterators – one
where the callee (the iterator) is closure converted (like C#, Python…) and the approach
to grab a closure in the caller with a light-weight or heavy-weight abortive construct
(as in Ruby and Scheme). &lt;/font&gt;&lt;a href="http://www.rubygarden.org/ruby?IterationStyles"&gt;&lt;font face=Arial&gt;Here
is a pleasant discussion on iteration styles.&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="FONT-SIZE: 12pt"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Finding
Yield the Magnificent&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Fixing the C# and Py approach requires two potentially
simple changes. Make the C# MoveNext() or the Py next() functions take an argument.
This is not strictly semantically correct, because this means that if MoveNext or
next are used to start the computation then the first value passed is ‘hanging in
space’. This fixes requirement 5. To fix 3 it is enough to create a new member in
the closure object that retains the return value. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;While this might be all very well in Py, its probably
not as easy in C# or other strongly typed systems since you hit a syntactic limitation
about where you express the return type of the function and the types of the value
that yield returns to the function. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Fixing lockstep in a blocks/internal iterators/scheme-ruby-style
approach can be done if it is possible to create a combinator that takes multiple
iterators and a block that takes multiple values and does an iterator equivalent of
scheme’s ‘apply’. I don’t if such an apply-iterator operator exists. Maybe this was
the difficulty they weren’t built into ruby in the first place. I don’t have a solution
to interleaved iteration when it’s the caller that is closure converted – there is
probably no valid general purpose transformation of this sort possible. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;There,
I am glad all of this is said finally. I knew it all at the back of my mind as a shapeless
dark area in my understanding of yield from which I could derive working knowledge,
but nothing quantified. What started off all of this is that I finally needed a yield
that did all of the above – that seemed to be the only natural way to express a particular
algorithm. Now that all of this is said its quantified, weather it is all right or
wrong. I will be happy to see what ideas you can contribute to the above discussion.
I would also like work of the apply-iterator operator or if such a beast exists and
you know about it, let me know. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;I will
get down to proof-reading this soon.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=21892608-a48c-414b-930f-d0ddecbc5b07" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,21892608-a48c-414b-930f-d0ddecbc5b07.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=51acd1d2-cc59-4312-9d1a-b250fa295c5b</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,51acd1d2-cc59-4312-9d1a-b250fa295c5b.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,51acd1d2-cc59-4312-9d1a-b250fa295c5b.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=51acd1d2-cc59-4312-9d1a-b250fa295c5b</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <title>The Mini Kanren Logic System for the CLR</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,51acd1d2-cc59-4312-9d1a-b250fa295c5b.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/10/07/TheMiniKanrenLogicSystemForTheCLR.aspx</link>
      <pubDate>Fri, 07 Oct 2005 18:45:47 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is an implementation of the &lt;/font&gt;&lt;a href="http://kanren.sourceforge.net/"&gt;&lt;font face=Arial&gt;Mini
Kanren logic system&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; for the CLR. This was
done last night, so you can take it with a pinch of salt. It does not cover the full
set of constructs that original MK system covers. &lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,f2b9574a-cbb3-472c-aa7d-0cfe9f7b13d7.aspx"&gt;Here
is a overly simplified introduction to miniknaren&lt;/a&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This implementation is done in &lt;/font&gt;&lt;a href="http://research.microsoft.com/Comega/"&gt;&lt;font face=Arial&gt;Cw,
the experimental language from MSR&lt;/font&gt;&lt;/a&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;.
You will need the COmega compiler if you wish to compile the source. &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This implementation covers the basic ‘run’, ‘all’ and
‘conde’ constructs. You do not need a ‘fresh’ because I use the Cw type system and
scoping to give me the equivalent of fresh. MiniKanren is implemented as an embedded
language in scheme – so you get to do relational programming and then drop into scheme’s
functional host language as need be. Since this implementation runs over Cw, this
extends and hence you get a combination of a declarative logic programming system
on top of everything that is Cw. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am considering adding some more constructs and maybe
a relational arithmetic system. I am also considering extending Cw syntax using an
external precompiler so that it becomes as little more natural to write relational
programs. The present ‘syntactic beauty’ is well a little lacking..&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;All that said, &lt;/font&gt;&lt;a href="http://www.thinkingms.com/pensieve/content/binary/mk.cw"&gt;&lt;font face=Arial&gt;here
are the sources from last night&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;q
= new Var();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;a
= new Var();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;b
= new Var();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;c
= new Var();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;res
= Mk.run( q,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Mk.eq(
q, new object[]{ a, b}),&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Mk.eq(
a, c ),&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Mk.eq(
c, 10),&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Mk.conde(&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;new
goal[]{ Mk.eq(b, 5) },&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;new
goal[]{ Mk.eq(b, 10) },&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;new
goal[]{ Mk.eq(b, 20) },&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;new
goal[]{ Mk.eq(b, 25) },&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;new
goal[]{ Mk.eq(a, 50) }&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt; 
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;//res
is the potentially infinite lazy evaluated set&lt;span style="mso-tab-count: 5"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
r&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;= res.{ return Var.ToString( it );
};&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;r.{
Console.WriteLine( it ); };&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;
&lt;o:p&gt;
&lt;font face=Arial&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A logic programming system is a great way to implement
solutions to several kinds of problems like dependency analysis, all searching any
relational space (ex: &lt;/font&gt;&lt;a href="http://lambda-the-ultimate.org/node/view/1001"&gt;&lt;font face=Arial&gt;A
Type Discipline for Authorization Policies&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Disclaimer: 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(I am
not responsible for your divergences). 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(I am
also not responsible for any halting problems with your compilation process).&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(The full
credit of MK goes to its original authors. This implementation is merely a transliteration
with a certain imperative flavor added).&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=51acd1d2-cc59-4312-9d1a-b250fa295c5b" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,51acd1d2-cc59-4312-9d1a-b250fa295c5b.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=5fbe2a6b-4c5b-4c62-91d5-a8b14b851df2</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,5fbe2a6b-4c5b-4c62-91d5-a8b14b851df2.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,5fbe2a6b-4c5b-4c62-91d5-a8b14b851df2.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=5fbe2a6b-4c5b-4c62-91d5-a8b14b851df2</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <title>Static Typing where Possible, Dynamic Typing when Needed</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,5fbe2a6b-4c5b-4c62-91d5-a8b14b851df2.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/08/01/StaticTypingWherePossibleDynamicTypingWhenNeeded.aspx</link>
      <pubDate>Mon, 01 Aug 2005 19:30:34 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I just finished reading Erik Meijer and Peter Drayton’s
work-in-progress paper on programming languages and type systems. The paper as correctly
noted in the beginning is written-to-provoke and I think this line of work is required
today when technologies like .Net and the JVM have opened up possibilities of experimenting
with languages and language systems and potentially reduced barriers for acceptance
of new languages. The value proposition the expressiveness of a new language provides
can be more readily accepted today in frameworks like .Net where a programmers existing
knowledge/use of an API and an existing code base will not be lost by switching over
to the new language. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The paper touches a large variety of topics and is
more in brain dump of thoughts around the general area of type systems in dynamic
and static languages. They also have some very interesting pointers and references. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The papers discusses type inference, programming by
contract as opposed to having the type system as the only means of contract, subtyping
and potentially expressing subtyping as programming by contract, type-directed lifting
in Cw and how that can be used as opposed to non-intuitive reflective code. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The paper talks mentions the SqlDataReader – even if
you don’t grok anything else in the paper, try and understand this part and try and
see the need to a better programming language model – especially if you have ever
worked on the data tier or business logic tier of an n-tier data centric application. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The paper also mentions lazy evaluation and about potentially
deprecating the need for using eval if you have a better system in place for most
of the common uses of eval. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;On the whole it’s a paper that worth your time if you
have started thinking about why when using C++ its so damn hard to get anything right,
why C# cant be a little more flexible when handling collections, XML like or SQL like
data and why languages like your pet python or ruby don’t make the mainstream.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://pico.vub.ac.be/~wdmeuter/RDL04/papers/Meijer.pdf"&gt;&lt;font face=Arial&gt;http://pico.vub.ac.be/~wdmeuter/RDL04/papers/Meijer.pdf&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=5fbe2a6b-4c5b-4c62-91d5-a8b14b851df2" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,5fbe2a6b-4c5b-4c62-91d5-a8b14b851df2.aspx</comments>
      <category>Languages</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=7e237ca9-7168-45c3-a2fc-788f8235bc26</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,7e237ca9-7168-45c3-a2fc-788f8235bc26.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,7e237ca9-7168-45c3-a2fc-788f8235bc26.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=7e237ca9-7168-45c3-a2fc-788f8235bc26</wfw:commentRss>
      <slash:comments>9</slash:comments>
      <title>The Emperor’s new Netshortcut Language</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,7e237ca9-7168-45c3-a2fc-788f8235bc26.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/05/07/TheEmperorsNewNetshortcutLanguage.aspx</link>
      <pubDate>Sat, 07 May 2005 17:32:28 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;For a long time I have been using this little program
misnamed netshortcut. It’s a little command line that pops when you press a key-combination;
commands that it supports are configured into a rules file using a rudimentary declarative
language that evolved ‘as-appropriate’. Read more about it here &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/homepage/work/netshortcut/netshortcut.htm"&gt;&lt;font face=Arial&gt;http://www.thinkingms.com/pensieve/homepage/work/netshortcut/netshortcut.htm&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;While I had been using NS for a while, there was this
growing frustration that it could be made to do more things – if it had a better designed
language underlying it. This frustration continued for a long time, until sometime
early last year I got to working it out. I had lots of help from &lt;/font&gt;&lt;a href="http://blogs.applibase.net/sidharth/"&gt;&lt;font face=Arial&gt;Sid&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;,
against whom I would bounce the creations of my genius. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Today the notebook in which we had worked out our plans
resurfaced after a year. I didn’t want to loose this stuff again, though it was going
to be an embarrassment for the future – and hence this blog entry. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I remember Sid saying that is some south american there
are a sort of monkeys that have really long tails that hang down branches when they
sit. And I say “so?”. And he says ‘So maybe you can use that idea in your language’.
I ponder that for a while and then figure that I won’t be so useful. I hindsight,
maybe Sid was right after all… &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So here is the language, in wonderfully non formal
description - &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&amp;lt;pattern&amp;gt; {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;do
( &amp;lt;args&amp;gt; ) { &amp;lt;code&amp;gt; }&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;is
{ &amp;lt;value&amp;gt; }&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;comment
&amp;lt;string&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;def
&amp;lt;ident&amp;gt; {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;render
&amp;lt;password | list | text&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;include
&amp;lt;filename&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;alias
&amp;lt;pattern&amp;gt; &amp;lt;name&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;code
{ &amp;lt;code&amp;gt; } 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;one
or more pattern blocks&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;That’s it. All programs have to begin in some scope,
so this language’s global scope is same as the scope that corresponding to the inside
of an def &amp;lt;ident&amp;gt; { &amp;lt;this is the global scope&amp;gt; }.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Remember that this language is fundamentally declarative
is used primarily as metdata for a command line. The standing idea was the code blocks
inside do() {} and is {} would be handled by a regular programming language that allowed
interpreter hosting – the idea was to go with ruby then.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;There is also the notion that braces can be eliminated
except for do and is blocks. If a var does not have a do or is block is its value
is simple returned back up the tree.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is a definition for supporting invoking the browser
to do a google search. The user at the NS command line would type something like this
– &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;gg &amp;lt;what to search for&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Imagine we have a file called library.rb that has &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;def browser(url)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;#
invoke browser with specified url&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;def urlEncode(value)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;#return
a urlEncoded version of value&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This will be the NS rules file – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;include “library.rb”&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;gg { 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;do
(arg ) { browser(“www.google.com?q=#{arg}”) } 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;comment
“Search Google”&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;def
arg {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;*
{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;is
{ urlEncode(value) }&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Note that ‘value’ that is passed to the urlEncode()
is a special variable that holds the value of the current match (* matches to anything). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now this does look a little clunky (and yes unintuitive)
but with the defaults and with some braces reduction it would look like this – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;include “library.rb”&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: blue"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: blue"&gt;&lt;font face="Courier New"&gt;gg do(arg){ browser(“www.google.com?q=#{urlEncode(arg)}”)
} comment “Search Google”&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue; mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Neat? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;The
language actually allows for a 
&lt;st1:place w:st="on"&gt;LOT&lt;/st1:place&gt;
of flexibility for controlling what gets executed for what the user types, what comments
are displayed, how the UI gets rendered etc. I cant really describel all of that here,
but this is the essence -&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;The
lowest do() {} block that is satisfied is executed wrt a command. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;The
is{} block at any level computes a value that may serve as a argument value to a do
block higher up the tree. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;The
code {} blocks are executed in pre-order (when going down the tree)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;The
do(){} and is{} blocks are executed in post-order after the command is completed. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Any
{} other than for do, is and code can be skipped. Doing so reduces the rest of the
line to the scope of the starting instruction’s block. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The new NS is also to support a notion of setting scope.
You use &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: maroon"&gt;&lt;font face="Courier New"&gt;@ &amp;lt;rest of command here&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;to set scope. For example, if you are going to be doing
a lot of google searches, you do a &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: blue; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;@
gg 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;And from that point on whatever you type at the command
line will the value of the arg parameter of the do(){} of the gg pattern. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I have not really go down to implementing this yet. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Someday… &lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=7e237ca9-7168-45c3-a2fc-788f8235bc26" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,7e237ca9-7168-45c3-a2fc-788f8235bc26.aspx</comments>
      <category>Languages</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=e24b5ddb-bae0-4d61-bf3f-d77240f3befc</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,e24b5ddb-bae0-4d61-bf3f-d77240f3befc.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,e24b5ddb-bae0-4d61-bf3f-d77240f3befc.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=e24b5ddb-bae0-4d61-bf3f-d77240f3befc</wfw:commentRss>
      <title>Scheme Compilation: Added variable argument support</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,e24b5ddb-bae0-4d61-bf3f-d77240f3befc.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/04/13/SchemeCompilationAddedVariableArgumentSupport.aspx</link>
      <pubDate>Wed, 13 Apr 2005 14:49:55 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Refers:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://roshanj/blog/CommentView,guid,1c67665f-79f0-450f-8062-1e18c15d1247.aspx"&gt;&lt;font face=Arial&gt;Part
1 - The weekend ‘Scheme’ compiler in C#&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://roshanj/blog/CommentView,guid,05bf137f-9f91-4395-a49a-bb23c07cddfd.aspx"&gt;&lt;font face=Arial&gt;Part
2 - Compiling Scheme style function dispatch to IL&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;This is fun. I added variable argument support.
So everything is of type &lt;/font&gt;&lt;span class=CodeSnippetChar&gt;&lt;font face="Courier New"&gt;void
foo(object[] args)&lt;/font&gt;&lt;/span&gt;&lt;font face=Arial&gt; now. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Effectively I can have the full set of lambda signatures
-&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(lambda () &amp;lt;code&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(lambda (a) &amp;lt;code&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(lambda (a b) &amp;lt;code&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(lambda a &amp;lt;code&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(lambda (a . b) &amp;lt;code&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Lambda’s now have a preamble that maps formal parameters
and does arity checking. In the cases of lambda’s I populate I create one local variable
each to represent each parameter. When there is a variable number of arguments I create
a scheme list out of the section of the object[] and assign the list to the local
variable. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I hope all this is consistent with scheme. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/content/binary/scmc.zip"&gt;&lt;font face=Arial&gt;Download&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=e24b5ddb-bae0-4d61-bf3f-d77240f3befc" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,e24b5ddb-bae0-4d61-bf3f-d77240f3befc.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=05bf137f-9f91-4395-a49a-bb23c07cddfd</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,05bf137f-9f91-4395-a49a-bb23c07cddfd.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,05bf137f-9f91-4395-a49a-bb23c07cddfd.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=05bf137f-9f91-4395-a49a-bb23c07cddfd</wfw:commentRss>
      <title>Compiling Scheme style function dispatch to IL</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,05bf137f-9f91-4395-a49a-bb23c07cddfd.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/04/13/CompilingSchemeStyleFunctionDispatchToIL.aspx</link>
      <pubDate>Wed, 13 Apr 2005 09:53:37 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Refers:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.thinkingms.com/pensieve/CommentView,guid,1c67665f-79f0-450f-8062-1e18c15d1247.aspx"&gt;&lt;font face=Arial&gt;Part1
- The weekend ‘Scheme’ compiler in C#&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The compiler as of now does not do functions with variable
arguments. In scheme functions like + can take any number of arguments. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Function
Definition and Variables&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You right a function – more correctly a lambda in scheme
like this (lambda &amp;lt;arguments&amp;gt; &amp;lt;code&amp;gt;) and you bind it to a variable like
so &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(define foo (lambda &amp;lt;args&amp;gt;
&amp;lt;code&amp;gt;))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Effectively foo is a variable that can hold any type
– at this point of time it is bound to the lambda. The way I represent this in the
compiler is by creating foo to be of type object and then assigning to it a delegate
instance which will invoke the function generated corresponding to the lambda.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The equivalent of &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;object lambda1(&amp;lt;args&amp;gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;delegate object call_lambda1(&amp;lt;args&amp;gt;);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;object foo = new call_delegate1(lambda1);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This means that every function call via foo, basically
causes a type cast from object to the corresponding delegate type and then an invocation
via indirection. This is certainly slower than direct function calls, but this is
atleast a close enough mapping to the semantics of scheme. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Function
Dispatch&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Looking at the above its easy to see that I will need
delegates types of various arities and function dispatch will happen accordingly.
So when compiling &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(foo 1 2)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I know that foo is some value that is of delegate type
that will take two arguments. I don’t really have to know the function that its bound,
I just need a guarantee of the arity of the function and then I can invoke it. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The above call will get compiled to the following in
IL &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon"&gt;&lt;font face="Courier New"&gt;ldsfld&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;object
Program::foo&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon"&gt;&lt;font face="Courier New"&gt;castclass&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;[SchemeLibs]SchemeLibs.call2&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon"&gt;&lt;font face="Courier New"&gt;ldc.i4&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0x1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon"&gt;&lt;font face="Courier New"&gt;box&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[mscorlib]System.Int32&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon"&gt;&lt;font face="Courier New"&gt;ldc.i4&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0x2&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon"&gt;&lt;font face="Courier New"&gt;box&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[mscorlib]System.Int32&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon"&gt;&lt;font face="Courier New"&gt;callvirt&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;instance
object [SchemeLibs]SchemeLibs.call2::Invoke(object, object)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;- where call2 is a predefined delegate that takes two
parameters. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Problems
with variable argument dispatch&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The problem with functions with variable arguments
is this. When the compiler sees (foo 1 2) &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;what can it conclude about the arity of the function?
With variable arguments, it can only say that foo is a delegate that points to function
that requires not more that 2 mandatory arguments. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;But that’s not too good in the IL world because the
opcodes that you need to call functions with variable arguments are different from
the opcodes that take a fixed count of arguments. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In the clr world there are two approaches to passing
variable arguments to functions that I am aware of. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;params
array&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Firstly what C# officially does which is &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;void foo(params object[] args)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;foreach(object
arg in args)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face="Courier New"&gt;foo(1, 2, 3, 4);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you look at this in IL the compiler basically creates
an array in the caller, fills it with the arguments and then calls the function with
an array as the parameter. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;arglist&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The second approach - unofficially what C# does is
the real way of supporting variable arguments at the CIL level using the IL instruction &lt;i style="mso-bidi-font-style: normal"&gt;arglist. &lt;/i&gt;Here
is an example from Vijay Mukhi’s book on IL – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;.method
public hidebysig static vararg void abc(int32 i) il managed&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;.locals
(value class [mscorlib]System.ArgIterator V_0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ldloca.s&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;V_0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//create
the arglist object&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;arglist&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;call&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;instance
void [mscorlib]System.ArgIterator::.ctor&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: 0.5in"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;(value
class [mscorlib]System.RuntimeArgumentHandle)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;br.s&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;IL_001d&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//get
one argument at a time 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;IL_000b:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldloca.s&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;V_0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;call&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;instance
typedref [mscorlib]System.ArgIterator::GetNextArg()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;refanyval&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;[mscorlib]System.Int32&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//do
something with the value here&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ldind.i4&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;call&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void
[mscorlib]System.Console::WriteLine(int32)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//get
the next ones index&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;IL_001d:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldloca.s&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;V_0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;call&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;instance
int32 [mscorlib]System.ArgIterator::GetRemainingCount()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ldc.i4.0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;bgt.s
IL_000b&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ret&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: maroon; mso-bidi-font-size: 12.0pt"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This does have an equivalent in C# via an undocumented
(yes!! &amp;lt;insert swear word here&amp;gt;) keyword called __arglist. For more on this
take a look at &lt;/font&gt;&lt;a href="http://vijaymukhi.com/documents/books/ilbook/chap12.htm"&gt;&lt;font face=Arial&gt;Vijay
Mukhi’s discussion on Arrays&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; and &lt;/font&gt;&lt;a href="http://www.eggheadcafe.com/articles/20030114.asp"&gt;&lt;font face=Arial&gt;Undocumented
C# Types and Keywords&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; by Peter Bromberg
(a C# MVP).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you look at both of these, you see that the code
generator of the compiler has to be able to look at the call (foo 1 2) and determine
what instruction to generate. There is really no way I can determine the runtime type
of foo. (Yes there are optimization possible in certain limited cases, but in a general
sense no).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This has me thinking that the only way to solve the &lt;i style="mso-bidi-font-style: normal"&gt;problem&lt;/i&gt; might
be to always treat all function calls as calls with variable arguments. Yes, I know
that’s bad. So now function dispatch will have to go through the overhead of &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;type
casting a an object to delegate type&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;create
a data structure for the variable arguments (for both the params and arglist case)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;call
indirectly via a delegate&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am tempted to go with params instead of arglist for
implementing variable arguments for a bunch of reasons. Both create some sort of GC
managed list structure for extra parameters. Its just that params has a more logical
mapping in the C# world – so it would be easier to implement some library functions
in C# that take only one argument of the form object[]. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you have a better idea about how to do function
dispatch that accommodates for variable arguments, let me know. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=05bf137f-9f91-4395-a49a-bb23c07cddfd" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,05bf137f-9f91-4395-a49a-bb23c07cddfd.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=1c67665f-79f0-450f-8062-1e18c15d1247</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,1c67665f-79f0-450f-8062-1e18c15d1247.aspx</pingback:target>
      <dc:creator>Roshan</dc:creator>
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,1c67665f-79f0-450f-8062-1e18c15d1247.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=1c67665f-79f0-450f-8062-1e18c15d1247</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <title>The weekend ‘Scheme’ compiler in C#</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,1c67665f-79f0-450f-8062-1e18c15d1247.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/04/11/TheWeekendSchemeCompilerInC.aspx</link>
      <pubDate>Mon, 11 Apr 2005 14:29:27 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="COLOR: #003300; FONT-FAMILY: 'Times New Roman'"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;This
blog isn’t dead, it just smells that way. Actually, we have been having trouble with
our ISP – something configuration has changed that causes the worker process in which
context out web-application runs, to not have write permissions to the web folder
where the entries and comments are stored. So that means that I cannot make blog entries
and no one cane post comments. We need to have this sorted out or move to another
ISP real quick. For now my solution is to generate the blog entry xml file on my local
computer and upload it via ftp. That’s how you are seeing this entry.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now to the real topic of this post - I have been toying
around with Scheme for some time now – I would like to say a long time – but considering
how long scheme has been around (as opposed to say C#), my time is not that long. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Over the weekend (literally) I have made for myself
a compiler that compiles a language that has a lot of braces. I would really like
to say that it is scheme – it is not – but it is very scheme-like. Why it is not scheme
-&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;It
is a subset of the language&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;It
has some differences in semantics even in the subset that I managed to implement&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Sometime last Thursday I watched a 90 minute video
that shows how one can write a &lt;/font&gt;&lt;a href="http://lambda-the-ultimate.org/node/view/349"&gt;&lt;font face=Arial&gt;Scheme
to C compiler&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. &lt;/font&gt;&lt;a href="http://blogs.applibase.net/sidharth"&gt;&lt;font face=Arial&gt;Sidharth&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; originally
pointed me to this. Well, I didn’t watch all 90 minutes – shortly after the 60&lt;sup&gt;th&lt;/sup&gt; minute
or so I jumped up all charged up, ready to write a scheme compiler. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What the video showed me is how to solve some hard
problems in scheme compilation – basically how get rid of closures and continuations.
The video shows you how to do a closure conversion and CPS conversion. Those very
two issues about scheme compilation that I had nagging for sometime – watching the
video took them away. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is the subset of scheme that I implemented so
far. It has support for &lt;i style="mso-bidi-font-style: normal"&gt;lambda, define, if&lt;/i&gt; and
lists. In terms of library which is in C# and is extensible and I have +, =, car,
cdr, cons, display, remainder, newline etc.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So effectively I can compile code like this &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(define print (lambda (s)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(display
"Value is ")&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(display
s)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(newline)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(define gcd (lambda (a b)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(= b 0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;a&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(gcd
b (remainder a b)))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(print (gcd 50 70))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;and compile it to generate a .Net exe that actually
runs :)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This has been really good fun and a rather creative
thinking exercise. I currently plan to take it forward and implement a few more things
I am curious about. Its good fun to see what code like this does to your thinking
about things. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Right now the code flow of the compiler is structured
like this – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Scanner -&amp;gt; Parser -&amp;gt; [Abstract Syntax Tree] -&amp;gt;
Code generator -&amp;gt; exe&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The once I have a stable code generator, I am expecting
that instead of focusing on being able to compile every construct in scheme, I can
translate constructs down into the simpler constructs which the code generator already
handles. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;For example I don’t intend to compile a ‘cond’ statement
– instead I would take the AST that has the ‘cond’ and transform it into an AST which
can the ‘cond’ replaced with a nested ‘if’. Similar closure conversion and CPS conversion
(continuation passing style conversion) would be other AST transforms. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So the code flow would be like this – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Scanner -&amp;gt; Parser -&amp;gt; [AST] -&amp;gt; AST Transforms
-&amp;gt; [AST] -&amp;gt; Code generator -&amp;gt; exe&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Once I have the present code a little stabilized and
I have a framework for doing tree transforms, I should have a fairly complete implementation
of a scheme like language. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;Things I cant solve - &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Why I say scheme-like language is because I doubt if
I will ever actually implement a whole standards compliant system – simply for the
sheer effort. That aside I presently don’t know enough to be able to compile some
aspects of the language. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In scheme not many things have special status. As an
example variable name is simply a binding to some value.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So I can say -&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(define x (lambda (a) (+ a 10))) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;which binds variable x to a lambda (a function) that
takes a parameter and adds 10 to it and returns it. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now I can call it and assign the result to another
variable ‘a’ -&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(define a (x 10))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now in the same program I can define x to be something
else, say just a number… &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So typing of variables go for a toss. Similarly I cannot
really hardcode any function calls in the generated code – I have to indirect them
through a variable that holds a delegate, because at runtime I cannot really know
which function that variable is bound to. But those are solvable problems.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The hard problem comes up when you deal with what scheme
calls special forms. As an example ‘if’ is a special form. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(if (= a b) (display a) (display
b))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here either value of ‘a’ is displayed, or value of
b is displayed. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now it is not possible to implement ‘if’ using a function
call. Because whenever you call a function, all the arguments to the function are
fully evaluated. So if there was a function called ‘if’ the condition, then and else
parts would be evaluated before the ‘if’ function is called. So in this case the user
would see both ‘a’ and ‘b’ being displayed. So ‘if’ has to be treated differently
by the compiler and I have to generate test and branch instructions for the ‘if’.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The problem comes in the fact that the user can perfectly
well say something like this – &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(define if 10)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So from now on ‘if’ is 10.. that’s crazy because that’s
a runtime condition, whereas my compiler has already generated test/branch code for
the if. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When writing a compiler and I see ‘if’ I emit intermediate
code which tests a condition and braches to the right code block for execution. If
at runtime the meaning of the ‘if’ itself changes then the branching and compile time
generated code has no meaning. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You may argue that in the case of ‘if’, I can solve
the problem by having variable that indicates the current value of ‘if’ and at compile
time I can generate code for an additional check with this variable. However that’s
a limited hack… and it doesn’t explain what I will do when at runtime the meaning
of ‘define’ changes or the meaning of ‘lambda’ changes. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I cant solve this problem right now, I don’t know how
to – so I have given &lt;b style="mso-bidi-font-weight: normal"&gt;define&lt;/b&gt;, &lt;b style="mso-bidi-font-weight: normal"&gt;lambda&lt;/b&gt; and &lt;b style="mso-bidi-font-weight: normal"&gt;if&lt;/b&gt; a
special ‘keyword’ like status – similar to keywords in other languages where keywords
cannot be redefined to mean something else at runtime. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I don’t know if this is a problem I will be solving
also. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Things I hope I can implement &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;closures&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;continuations&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;more
special forms (list, quote)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;a
better function dispatch mechanism (generate the delegates types)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;tail
calls&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;-&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;cond,
let, letrec&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is my early ‘&lt;/font&gt;&lt;a href="http://www.thinkingms.com/pensieve/content/binary/scmc.zip"&gt;&lt;font face=Arial&gt;over-the-weekend’
quality scheme compiler for download&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. Use
with caution. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This also requires the elusive .Net 2.0. I am not releasing
source just yet, but it will come. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;However, if you are looking for an actual full fledged
compiler scheme compiler for .Net &lt;/font&gt;&lt;a href="http://www.gotdotnet.com/team/lang/"&gt;&lt;font face=Arial&gt;GotDotNet
lists&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; the following -&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;table class=MsoNormalTable style="mso-cellspacing: 1.5pt" cellpadding=0 border=0&gt;
&lt;tbody&gt;
&lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
&lt;td style="BORDER-RIGHT: #f2ecd7; PADDING-RIGHT: 0.75pt; BORDER-TOP: #f2ecd7; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #f2ecd7; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #f2ecd7; BACKGROUND-COLOR: transparent"&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.0pt"&gt;&lt;a href="http://rover.cs.nwu.edu/~scheme/"&gt;&lt;font size=2&gt;Scheme&lt;/font&gt;&lt;/a&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td style="BORDER-RIGHT: #f2ecd7; PADDING-RIGHT: 0.75pt; BORDER-TOP: #f2ecd7; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #f2ecd7; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #f2ecd7; BACKGROUND-COLOR: transparent"&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.0pt"&gt;&lt;font size=2&gt;&lt;font color=#000000&gt;Northwestern
University Hotdog Scheme&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 1"&gt;
&lt;td style="BORDER-RIGHT: #f2ecd7; PADDING-RIGHT: 0.75pt; BORDER-TOP: #f2ecd7; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #f2ecd7; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #f2ecd7; BACKGROUND-COLOR: transparent"&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.0pt"&gt;&lt;a href="http://radio.weblogs.com/0101156/stories/2002/03/19/tachy.html"&gt;&lt;font size=2&gt;Scheme&lt;/font&gt;&lt;/a&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td style="BORDER-RIGHT: #f2ecd7; PADDING-RIGHT: 0.75pt; BORDER-TOP: #f2ecd7; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #f2ecd7; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #f2ecd7; BACKGROUND-COLOR: transparent"&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.0pt"&gt;&lt;font size=2&gt;&lt;font color=#000000&gt;Tachy
(Scheme-like) language&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 2; mso-yfti-lastrow: yes"&gt;
&lt;td style="BORDER-RIGHT: #f2ecd7; PADDING-RIGHT: 0.75pt; BORDER-TOP: #f2ecd7; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #f2ecd7; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #f2ecd7; BACKGROUND-COLOR: transparent"&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.0pt"&gt;&lt;a href="http://www.cs.indiana.edu/~jgrinbla/index.htm"&gt;&lt;font size=2&gt;Scheme&lt;/font&gt;&lt;/a&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td style="BORDER-RIGHT: #f2ecd7; PADDING-RIGHT: 0.75pt; BORDER-TOP: #f2ecd7; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #f2ecd7; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #f2ecd7; BACKGROUND-COLOR: transparent"&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=2&gt;&lt;font color=#000000&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;
&lt;st1:place w:st="on"&gt;
&lt;st1:PlaceName w:st="on"&gt;
&lt;span style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.0pt"&gt;Indiana&lt;/span&gt;
&lt;/st1:PlaceName&gt;
&lt;span style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.0pt"&gt; 
&lt;st1:PlaceType w:st="on"&gt;University&lt;/st1:PlaceType&gt;
&lt;/span&gt;
&lt;/st1:place&gt;
&lt;span style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.0pt"&gt; Scheme.NET&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You may have more luck with these. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You may not be able to leave comments on my blog right
now. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Do send me mail for now roshan -dot- james -at- gmail
-dot- com.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=1c67665f-79f0-450f-8062-1e18c15d1247" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,1c67665f-79f0-450f-8062-1e18c15d1247.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=9cad9d1d-f339-43b4-b390-e365597875ed</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,9cad9d1d-f339-43b4-b390-e365597875ed.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,9cad9d1d-f339-43b4-b390-e365597875ed.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=9cad9d1d-f339-43b4-b390-e365597875ed</wfw:commentRss>
      <title>Vulcan: Binary transformation in a distributed environment</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,9cad9d1d-f339-43b4-b390-e365597875ed.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2005/01/10/VulcanBinaryTransformationInADistributedEnvironment.aspx</link>
      <pubDate>Mon, 10 Jan 2005 04:41:30 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The little public information about Vulcan &amp;#8211; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;MSR-TR-2001-50&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Vulcan:
Binary transformation in a distributed environment&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Andrew Edwards; Amitabh Srivastava; Hoi Vo&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;April 2001&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://research.microsoft.com/research/pubs/view.aspx?type=Technical%20Report&amp;amp;id=455"&gt;&lt;font face=Arial&gt;http://research.microsoft.com/research/pubs/view.aspx?type=Technical%20Report&amp;amp;id=455&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=9cad9d1d-f339-43b4-b390-e365597875ed" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,9cad9d1d-f339-43b4-b390-e365597875ed.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=86e483c0-e90b-4af5-8c46-529bf5f942df</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,86e483c0-e90b-4af5-8c46-529bf5f942df.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,86e483c0-e90b-4af5-8c46-529bf5f942df.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=86e483c0-e90b-4af5-8c46-529bf5f942df</wfw:commentRss>
      <title>Scheme - again</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,86e483c0-e90b-4af5-8c46-529bf5f942df.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/11/23/SchemeAgain.aspx</link>
      <pubDate>Tue, 23 Nov 2004 01:51:44 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Over the months I had slowly lost touch with Scheme,
with so much happening in life. Today I saw some scheme code again and somehow just
looking at it made me happy. Some kind of inherent simplicity in seeing those brackets
and that indentation style &amp;#8211; something vague familiarity of old friendship.
It was weird.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;No no, I am not cracking up and I am still a good old
pure imperative languages programmer at heart and yes (Small talk guys please stand
to the corner), I believe that C++ is a OO language and I still like .Net and C#.
But all said and done, I think I like scheme &amp;#8211; need to get back to some old
scheming as soon as time allows. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Digressing - been musing about dynamic languages a
bit more. The real reason I have not been writing too much about it is because of
the feeling that I am going to sound stupid because I don&amp;#8217;t know enough. I think
I am going to let go of that and take the risk of looking foolish for a bit and start
writing down things as I go ahead. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is a bunch of things that could/would fall under
the general umbrella of the lose term &amp;#8211; dynamic languages &amp;#8211; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;1)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;closures&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;2)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;iterators&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;3)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;coroutines&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;4)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;continuations&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;5)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;mutable
types&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;6)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;typeless
variables&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;7)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;dynamic
method dispatch&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;8)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;eval&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I don&amp;#8217;t want to get into method dispatch and
sub-classing mechanisms here, but I think the above is a general list. Any biggies
I have missed? Lets see if there are any appropriate mappings we can find in the CLR
and such. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The iterators and closures are solved problems &amp;#8211;
or atleast are largely solved problems in C# 2.0 (yes I know we can&amp;#8217;t do ref
variables &amp;#8211; I think that&amp;#8217;s ok for now &amp;#8211; I will be happy if you have
an answer)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;There are solutions to most of the others lying around
in one way or the other in Jim&amp;#8217;s IronPython and the lesser loved Jscript.Net
compiler that ships in source form with Rotor. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Does anyone know where I can find a readable description
of how a scheme compiler (not interpreter) would work?&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=86e483c0-e90b-4af5-8c46-529bf5f942df" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,86e483c0-e90b-4af5-8c46-529bf5f942df.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=61e018ed-85a6-42ff-ab97-9f2dc7ea342d</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,61e018ed-85a6-42ff-ab97-9f2dc7ea342d.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,61e018ed-85a6-42ff-ab97-9f2dc7ea342d.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=61e018ed-85a6-42ff-ab97-9f2dc7ea342d</wfw:commentRss>
      <title>Dynamic Languages on the CLR – Part 2</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,61e018ed-85a6-42ff-ab97-9f2dc7ea342d.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/11/22/DynamicLanguagesOnTheCLRPart2.aspx</link>
      <pubDate>Mon, 22 Nov 2004 08:45:54 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;a href="/CommentView,guid,de242cdc-412f-4de0-b095-b1d943f0f9eb.aspx"&gt;Dynamic
Languages on the CLR &amp;#8211; Part 1&lt;/a&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Today I came across a paper written in 1996 at MIT
that spoke of &lt;/font&gt;&lt;a href="ftp://publications.ai.mit.edu/ai-publications/pdf/AIM-1576.pdf"&gt;&lt;font face=Arial&gt;Dynamic
Languages implementation on the JVM&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. The
paper is an interesting read and pleasant because it isn&amp;#8217;t dotted with arcane
notational jing-bang and actually talks about real implementation issues. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The paper is written by Olin Shivers of MIT, &lt;/font&gt;&lt;a href="http://www.ai.mit.edu/people/shivers/advisor-stmt-original.txt"&gt;&lt;font face=Arial&gt;interesting
person&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; &amp;#8211; ha ha, actually this is &lt;/font&gt;&lt;a href="http://www.ai.mit.edu/people/shivers/"&gt;&lt;font face=Arial&gt;the
real link&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The first section address the issues of optimization
of small scalar data types like integers which cannot actually afford to have dynamic
lookup. The solution he proposes entails an assumption to be imposed on pointer types
&amp;#8211; so that small values can be held immediately rather than via indirection.
For this purpose he recommends the addition of a type called an &lt;i style="mso-bidi-font-style: normal"&gt;ImmediateDescriptor&lt;/i&gt;.
I could not help smiling because this seems so much like a solved problem in the CLR
of today &amp;#8211; value types. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The second big issue that the paper brings is one of
custom operations that a particular language may require that the runtime may not
support. I don&amp;#8217;t really have an answer for this. The paper goes onto compare
this as being the inherent contradiction between RISC and CISC systems and adds the
angle of safety of the end programming construct. This is by far a brilliant piece
of thinking and these are the two suggestions primarily &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;1)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Build
it up in API&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;2)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Enable
the VM to have an extendable instruction set &amp;#8211; similar to micrcodes in a processor&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.25in; mso-list: l0 level2 lfo1; tab-stops: list 1.0in"&gt;
&lt;font color=#000000&gt;&lt;span style="mso-bidi-font-family: Arial; mso-fareast-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;a.&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Enable
compilability of such new instructions by compiling to a lower level more RISC instruction
set than the high level instruction set of the runtime&amp;#8230; &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am hoping to offset this second part by not affording
extensibility in the runtime and instead believing in some magical set of primitives.
I don&amp;#8217;t know about work that is actually being planned by the CLR team in this
regard, I wonder what they are planning. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=61e018ed-85a6-42ff-ab97-9f2dc7ea342d" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,61e018ed-85a6-42ff-ab97-9f2dc7ea342d.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=de242cdc-412f-4de0-b095-b1d943f0f9eb</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,de242cdc-412f-4de0-b095-b1d943f0f9eb.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,de242cdc-412f-4de0-b095-b1d943f0f9eb.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=de242cdc-412f-4de0-b095-b1d943f0f9eb</wfw:commentRss>
      <title>Dynamic Languages on the CLR – Part 1</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,de242cdc-412f-4de0-b095-b1d943f0f9eb.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/11/22/DynamicLanguagesOnTheCLRPart1.aspx</link>
      <pubDate>Mon, 22 Nov 2004 08:44:47 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It has been on my mind for a long time, to write about
this &amp;#8211; supporting dynamic languages on the most advanced runtime on the planet.
I have been having this pet project on the back of my mind, and figured that I should
probably write about it now. I was wondering how hard it would be to extend the CLR
in a fundamental way to support dynamic languages &amp;#8211; the idea here is not to
add a whole bloat of features to the CLR, but to try and identify a set of primitive
or simple rules/abstractions which when added to the CLR would enable implementation
of dynamic languages efficiently on the CLR.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;Why the CLR? Because the CLR is one of the fastest
runtimes/VMs out there; it was inherently designed to run multiple languages; runs
on a whole bunch of hardware and software platforms and has a very wide acceptance
in the industry; it is an open standard that is not owned by any company; and there
are atleast two publicly available implementations in source form &amp;#8211; which means
that it enables a language that previously had to lug along its own VM/interpreter &lt;i style="mso-bidi-font-style: normal"&gt;to
boldly go where no previous version has gone before.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/i&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Some smart languages like Groovy are doing this with
the JVM. I was hoping for a while that Ruby would &amp;#8211; but it turns out, after
several mails on the Ruby mailing list that Matz the creator of Ruby, has other plans.
Matz is writing his own VM for Ruby. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It looks like it&amp;#8217;s a season for writing multi-language
runtimes &amp;#8211; head of the pack being &lt;/font&gt;&lt;a href="http://www.parrotcode.org/"&gt;&lt;font face=Arial&gt;Parrot&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;,
the new VM for Perl 6. There is of date, little or no information available about
the actual architecture of Rite &amp;#8211; ruby&amp;#8217;s VM that Matz is working on. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What makes a runtime that supports dynamic languages
different from runtimes that are built to support statically typed OO languages &amp;#8211;
I don&amp;#8217;t have enough of a formal education or personal experience to answer that
straight out. That is one of the things that I hope to teach myself in coming time.
I can throw terms like dynamic method dispatch at you&amp;#8230; but essentially I don&amp;#8217;t
know if I can nail it down to a set of fundamental primitives that make all the difference. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is a blog entry about some of my early ramblings
on the topic. I am hoping to teach myself some of the difference by looking at the
opcode design for Parrot. I am expecting that there would be opcodes for runtime type
lookup, runtime method invocation etc etc &amp;#8211; does that solve the problem, I don&amp;#8217;t
know. It provides features that can be used to mitigate the problem, yes. In conjunction
with studying the architecture of Parrot, I am hoping to compare and contrast that
with what the CLR supports and see what is missing in the CLR. Again I am not expecting
much to be missing &amp;#8211; what I am expecting to be seeing be seeing is that a lot
of what Parrot provides as opcodes, the CLR would not natively provide, but would
instead be available as framework API.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;There is another source &amp;#8211; Jim Hugunin&amp;#8217;s &lt;/font&gt;&lt;a href="http://ironpython.com/"&gt;&lt;font face=Arial&gt;IronPython&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;.
Sometime early this year Jim Hugunin shocked the Python community and a large part
of the dynamic languages world by implementing a python version that ran on the CLR
&amp;#8211; it was faster that the classical C Python. Jim previously was known for his &lt;/font&gt;&lt;a href="http://hugunin.net/story_of_jython.html"&gt;&lt;font face=Arial&gt;Jython&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; &amp;#8211;
a Python that ran on the JVM &amp;#8211; but was a rather slow implementation. What Jim
has essentially done is that he has written a bunch of libraries to augment what the
framework provides and has used these liberally along with regular IL. Jim now works
for the CLR team at Microsoft. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Once I think I have an understanding of how the Parrot
opcodes makes it a better runtime for dynamic languages, looking at Jims work (which
is openly available) should give me a good idea of what primitives can be derived
and can be pushed into the CLR. That should be a good fun project to work on.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A lot of what I have typed would be plain common sense
for someone who was actually following the field. A whole bunch of things are getting
in the way of getting started, else I would have already.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=de242cdc-412f-4de0-b095-b1d943f0f9eb" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,de242cdc-412f-4de0-b095-b1d943f0f9eb.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=3913b965-6eb6-4b69-a64e-70c95a7331b5</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,3913b965-6eb6-4b69-a64e-70c95a7331b5.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,3913b965-6eb6-4b69-a64e-70c95a7331b5.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=3913b965-6eb6-4b69-a64e-70c95a7331b5</wfw:commentRss>
      <title>XEmacs, Editors and Learning more Scheme – for loops</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,3913b965-6eb6-4b69-a64e-70c95a7331b5.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/06/28/XEmacsEditorsAndLearningMoreSchemeForLoops.aspx</link>
      <pubDate>Mon, 28 Jun 2004 11:19:28 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I have been putting more of my free time into digesting
Scheme. I am now working on XEmacs. After several stops and starts with emacs in the
past, I am finally using it (might I add - productively) to write scheme code. I figured
that even if emacs is of no use to me for most of my work, I could atleast use it
to write scheme code. It should be good for that for sure. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Don&amp;#8217;t misunderstand me when I say this, because
you may have different opinion, especially if you have lived in Unix for a long time
&amp;#8211; which I haven&amp;#8217;t. XEmacs still leaves me feeling like I am taking piano
classes. I use Scite and Visual Studio for most of my day to day work.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Of
course, if I am writing a document, then it is Word. I also have a love-hate relationship
with Rob Pike&amp;#8217;s Sam editor. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;For a long time I used the old Turbo C++ IDE in DOS
(yes I am not ashamed to confess) and it served me rather well. After which it was
Visual Studio 5... it was a pain to use in some cases, but with this plug-in called
&amp;#8216;Whole Tomato&amp;#8217; that I used, it was a killer. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When I got started on Linux, editing was a real pain
&amp;#8211; it was like I had to learn to type all over again. That was major put-off.
As a matter of fact I figured that I could not suffer the &amp;#8216;miserable&amp;#8217;
editors they have there and so decided to write my own editor. (Yes, I was crazy enough
to try and write an editor instead of learning arcane key combinations&amp;#8230;) Of
course, since I could edit code on Linux, I decided to write my editor in a portable
way in DOS and then figure out how to take it to Linux.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;As most DOS code was written those days, I wrote interesting
text mode menu libraries and such other things that assumed that I had access to VGA
text buffer to access. Finally when I actually had something going, I decided to make
the big switch &amp;#8211; Prot to Linux. Almost immediately, I hit a blank wall. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The entire style of programming, with direct access
to video memory that was used to write large Text-UI based apps on DOS, was simply
non-existent in Linux. That, I still remember, was such a major put off that I was
going around cursing Linux to anyone who would listen to me. The only alternatives
that I was left with, was to use some editors that did old Word-Star like CTRL-K based
key combinations, which was rather irritating. I also spent half a day looking at
the ncurses lib that time, hoping for a way out. All I got was buggy behavior and
one buggy lib after the other and numerous dependencies on some .so or the other which
I had to go and find on the net .&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Finally my entire work on the editor on Linux got scratched
and I decided to turn it into a DOS only thing &amp;#8211; which I used for much after
that as file viewer. The thing was distributed as w.exe to my friends and the default
config file used to display multicolor menu and the title &amp;#8220;The Zen Masters Workbench&amp;#8221;.
In w.exe was viewer that could be given C like structures and could read data out
of binary files to match the structures. That became the original basis for the implementation
of my &lt;/font&gt;&lt;a href="http://ddl.sscli.net/"&gt;&lt;font face=Arial&gt;DDL language&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I don&amp;#8217;t know why I typed all that down&amp;#8230;
anyway here is the little bit of scheme code that implements a for-loop as a macro.
I know it is not much, but its good fun.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;(require (lib "defmacro.ss"))&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;(define-macro for &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(lambda
(init&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;cond&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;step&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;code)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let
((loop (gensym)))&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;`(let
,loop ,init&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;(if
,cond&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(begin &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;,code&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(,loop
,step)))))))&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;;see nested for loops&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;(for ((i 1)) (&amp;lt; i 10) (+ i 1)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(begin&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(for
((j i)) (&amp;lt; j 10) (+ j 1)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(begin&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(display
i)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(display
j)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(display
" ")))&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(newline)))&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Of course, written entirely in xemacs. One reason to
use xemacs over Scite is that it gives me this really nice syntax driven indentation.
The syntax high-lighting, for what I have seen, is pretty corny though. But on the
whole, good enough to write scheme code for now. :-)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you are starting out on Scheme and already know
how to program, I recommend Dorai Sitaram&amp;#8217;s &amp;#8220;Teach Yourself Scheme in
Fixnum Days&amp;#8221; as a starter. The SICP is a lovely text as well and full of ideas,
but if you don&amp;#8217;t have lots or free time on your hands and are not the sort who
likes letting an idea go without giving it its due thought, then I wouldn&amp;#8217;t
recommend SICP. It will be a while before you get down to scheme-ing. Also Prof Kent
Dybvig&amp;#8217;s book on Scheme is good, but again if you are the impatient sort, the
DS book is the better choice.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In a few weeks I should get my copy of the Little Schemer,
I intend to be ready for it by then :-)&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=3913b965-6eb6-4b69-a64e-70c95a7331b5" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,3913b965-6eb6-4b69-a64e-70c95a7331b5.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
      <category>Zeitgeist</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=9c1c7164-5655-439c-9d3f-6bef419c1b25</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,9c1c7164-5655-439c-9d3f-6bef419c1b25.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,9c1c7164-5655-439c-9d3f-6bef419c1b25.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=9c1c7164-5655-439c-9d3f-6bef419c1b25</wfw:commentRss>
      <slash:comments>7</slash:comments>
      <title>Enter the Data Definition Language: a developer perspective</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,9c1c7164-5655-439c-9d3f-6bef419c1b25.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/06/25/EnterTheDataDefinitionLanguageADeveloperPerspective.aspx</link>
      <pubDate>Fri, 25 Jun 2004 12:07:53 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;(The following article
was originally written for the .Net Developer Journal where it featured in the Nov
2003 issue. This was co-written by Pooja and me and basically serves as an intoroduction
to our DDL language. The original language was co-written by us and two of our friends
Rakesh Nandakumar and Tony Sakariya as our final year college project. The DDL in
its present .Net avatar is work by Pooja and me. The copyright perios of this article
has expired, hence this post. You can find the article hosted on the magazine website
here: &lt;a href="http://www.sys-con.com/dotnet/article.cfm?id=460"&gt;http://www.sys-con.com/dotnet/article.cfm?id=460&lt;/a&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;.
I hope Pooja will be mirroring this article too) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;h1 style="MARGIN: 12pt 0in 3pt"&gt;&lt;font face=Arial color=#000000 size=5&gt;Enter the Data
Definition Language: a developer perspective&lt;/font&gt;
&lt;/h1&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 12pt"&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;Roshan
James &amp;amp; Pooja Malpani&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-SIZE: 12pt"&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;(Authors
of the DDL)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Greetings, In this short write-up we are going to discuss
our new language for the .Net platform called the Data Definition Language (DDL).
We hope that by the time you have finished reading this, you will want to log onto
the internet, download the DDL and try it for yourself (and drop us mail about it).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The DDL is a unique language that aims at solving a
common problem. We all would have faced situations where we needed to read data from
a file of some given format and there are no real library routines for this purpose,
other than the standard file handling libraries. In such cases, we would have to develop
code that will calculate the addresses of various values that we want to retrieve
from the file and write file handling code that will retrieve the data. While this
is probably feasible for simple file types, the need to support a complex file type,
or multiple file types or a changing file type can easily become a development bottleneck. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Once, we had to work with a development team that was
creating an application for analyzing data collected in aircraft black boxes. Data
dumps from black boxes have very complex formats. The team needed to read values of
various aircraft parameters such as left-aileron-angle, right-engine-exhaust-temperature
etc, which were scattered across various bits that seemed to have no respect for word
boundaries or any such thing. To add to the fray there was no apparent standard between
black box formats of the same manufacturer, version of the same aircraft or any such
thing. The team needed to have their product support multiple black box formats without
a huge development cycle between these. A little thought made it apparent that there
was no real solution to supporting data retrieval from arbitrary file formats. This
is the problem that the DDL was designed to solve. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;How does
the DDL understand the format of the file I want to read data from?&lt;/b&gt; The DDL is
a language. It is designed to be simple and intuitive for expressing data formats.
To develop a solution with the DDL a developer needs to first write a DDL script that
represents the file format. Once the script is developed, you can run the DDL engine/interpreter
on the script, provide the engine with your data file and you are ready to start reading
information out of the file. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So how can I use the DDL in developing an application?
The DDL engine is designed to be an interpreter that be hosted by any .Net application
&amp;#8211; which means that your VB.Net or C# programs can act as hosts for the DDL.
A typical DDL solution would consist of your parent application that does all the
UI and has all the business logic. This would host the DDL engine with which you can
programmatically interact. The DDL engine simply acts as a substitute for your complex
file handling code; it does not dictate what you do with the data that you have retrieved. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;
&lt;v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;
&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;
&lt;v:formulas&gt;
&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;
&lt;/v:formulas&gt;
&lt;v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"&gt;&lt;/v:path&gt;
&lt;o:lock v:ext="edit" aspectratio="t"&gt;
&lt;img height=242 src="content/binary/ddl-hosting.gif" width=363 border=0&gt;
&lt;/o:lock&gt;
&lt;/v:shapetype&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;font face=Arial color=#000000&gt;Hosting the DDL.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Once you have hosted the DDL engine, you tell it to
do tasks such as &amp;#8216;load this ddl script file&amp;#8217;, to make it understand your
file format. Then you tell it to &amp;#8216;use this data file&amp;#8217; so that it can apply
your ddl script (which defines the data format) of the actual data file. Then you
tell it &amp;#8216;give me the value of left-aileron-angle&amp;#8217; and the DDL engine looks
at the script, understands where in the data file &amp;#8216;left-aileron-angle&amp;#8217;
would exist and reads out the value for your host application. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;What
are the DDL script files like?&lt;/b&gt; The DDL language provides you with primitive types
that represent bits &amp;#8211; these are available from single bit definitions to 32
bit definitions. These are named i1 i2, i3 etc to i32. Variables can be declared to
represent any of these types. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-bidi-font-family: Arial"&gt;i16
width 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This represents a 16 bit value called width. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now declarations like this should be grouped into DDL
structures. Structures would look like this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;struct Window&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;i16 width&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;i16 height&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A DDL script file can contain multiple structures like
the one above. Similar to the declaration of primitive bit types you could also define
a structure to contain a member of another structure type.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;struct Bitmap&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i8
BitsPerPixel&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Window
w&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The DDL script requires that you mark one structure
in the script file as the &amp;#8216;init&amp;#8217; structure. The DDL uses the &amp;#8220;init&amp;#8221;
structure as the first structure of your data file &amp;#8211; the init structure is mapped
to offset zero of your data file. The init structures and its members (which maybe
instances of some of the other structures declared in the script file) are expected
to represent the entire data file. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;img height=242 src="content/binary/ddl-script-tree.gif" width=644 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;font face=Arial color=#000000&gt;The tree-like structure formed by structures in a DDL
script file.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The DDL structures are different in concept from structures
in languages such as C. The first difference is that a DDL structure can contain members
depending on conditions. Secondly, a member in a DDL structure simply represents a
region in the data file; an i8 type member would represent a byte-sized region. Members
in a structure have their offset addresses from the base address of the structure
automatically calculated or can have explicit addresses provided. This little script
demonstrates both of these. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;struct EmployeeData&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i32&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;empNumber&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i1&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;fPhoneNumberProvided&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i7&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;fUndefined&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;when(
fPhoneNumberProvided == 1 )&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i8[10]&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;phoneNumberString&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;};&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;@
0,0 i24 empSerialNumber&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i8
empDesigCode&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This simple script demonstrates some interesting things.
An instance of the EmployeeData structure will contain a member called phoneNumberString
of 10 bytes, only if the fPhoneNumberProvided flag bit is set. Similarly the notation
&amp;#8220;@ 0,0&amp;#8221; is an explicit address specification that causes the address of
the declaration immediately following it to fall at an offset of 0 bits from the start
of the structure. Thus, with respect to little-endian Intel architecture, the lower
3 bytes of empNumber are the empSerialNumber and the most significant byte stands
for the employee&amp;#8217;s designation code. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;img height=236 src="content/binary/ddl-data-layout.gif" width=633 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;font face=Arial color=#000000&gt;Layout of the structure with respect to the bits of
the data file. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The script also demonstrates a simple array of i8 (or
byte) type of ten elements. Unlike C, the size of an array can be specified via an
expression. To illustrate the power of arrays consider the following snippet that
uses the above employee structure.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;struct EmployeeHeader : init&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;i16
empCount&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;EmployeeData
[empCount] emps&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The first member decides the number of employees whose
data is provided and &amp;#8216;emps&amp;#8217; represents as array of EmployeeData types.
You can now ask the DDL engine for the designation code of the 5&lt;sup&gt;th&lt;/sup&gt; employee
and DDL engine sets about to determine the location of the 5&lt;sup&gt;th&lt;/sup&gt; employee
and retrieve its &amp;#8216;empDesigCode&amp;#8217; value for you. Now remember that the EmployeeData
had a member that would occur conditionally &amp;#8211; this means that the size of each
EmployeeData instance can be different. The DDL engine internally determines that
there is a dependency and checks the flag in each of the preceding EmployeeData instances
to determine the actual location of the 5&lt;sup&gt;th&lt;/sup&gt; instance that you requested. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The ddl script provides only a minimal set of programming
constructs whose purpose is centered on being able to define data formats. The present
ddl language is rich enough to support a wide variety of common file formats. There
may however be some format types that may not be expressible in the ddl or are hard
to express. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The DDL language has constructs for representing address
specs, size specs, conditional dependencies, different kinds of array constructs etc.
This is a just a brief description of the language, the complete language description
document is available from the homepage. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Hosting
the DDL Interpreter:&lt;/b&gt; This is probably the simplest part. Imagine that EmployeeHeader
and EmployeeData together formed a ddl file called employee.ddl and that we had a
data file in this format called empinfo.bin. The following C# snippet is all you will
need to start off using the DDL. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;using System;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;using System.DDL;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;class DDLTestClass&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
void &lt;/span&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;
&lt;st1:place&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;Main&lt;/span&gt;
&lt;/st1:place&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//initialise
the DDL&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ManagedDDLEngine
ddl = new ManagedDDLEngine();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ddl.LoadSourceFile("employee.ddl");&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ddl.OpenDataFile("empinfo.bin");&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ddl.InterpretData();
//this call is needed to map the scoure to the data&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine("No
of employees = {0}",&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ddl.GetValue("empCount"));
// GetValue() read the value of a variable&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//contents
of emps[0]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ddl.Seek(".emps:0");&lt;span style="mso-tab-count: 1"&gt; &lt;/span&gt;//seek
changes path into a member 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine("Data
of 0th Employee \n\t "+&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;"empNumber={0}", 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ddl.GetValue("empNumber"));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//contents
of emps[5]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ddl.Seek(".emps:5");&lt;span style="mso-tab-count: 1"&gt; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine("Data
of 5th Employee \n\t "+&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="FONT-SIZE: 8pt"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=FR style="FONT-SIZE: 8pt; mso-ansi-language: FR"&gt;"empNumber={0}
\n\t "+&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=FR style="FONT-SIZE: 8pt; mso-ansi-language: FR"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;"empDesigCode={1},
\n\t "+&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=FR style="FONT-SIZE: 8pt; mso-ansi-language: FR"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;"empSerialNumber={2}", 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=FR style="FONT-SIZE: 8pt; mso-ansi-language: FR"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ddl.GetValue("empNumber"),&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=FR style="FONT-SIZE: 8pt; mso-ansi-language: FR"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ddl.GetValue("empDesigCode"),&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span lang=FR style="FONT-SIZE: 8pt; mso-ansi-language: FR"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 8pt"&gt;ddl.GetValue("empSerialNumber"));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ddl.Dispose();
//clean up&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt"&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This little snippet loads the ddl with the script file
and a data file and reads values from it. This snippet does not show any of the error
handling code that would be required in a production quality application. One concept
you need to be familiar with is that of path. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The init structure is represented as &amp;#8220;.&amp;#8221;
(dot). Any member under it is represented using its member name. Any child of that
member is separated by a dot, and so on. If there is an array in the path, then the
array instance is separate by a &amp;#8220;:&amp;#8221; (colon). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Ex &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face=Arial color=#000000&gt;init.emp[0] will be represented as &amp;#8220;.emps:0&amp;#8221;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;At any point the GetValue() call will return the values
on any of the variables in the current path. The Seek() is used to set the current
path to another location, subsequent GetValue() calls will read values from that location.
Bit values that are read are treated as unsigned integer types. All values are returned
as &amp;#8216;double&amp;#8217; type.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A document describing the API exposed by the DDL is
available on the homepage for details. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;What
is available? &lt;/b&gt;The DDL engine itself is currently for download as System.DDL.dll.
This is a mixed mode .net assembly developed in Managed C++ and can be hosted in any
.net application. The entire source code of the DDL is also available for download.
The DDL is offered for use free of cost and is currently not under any licensing or
royalty restrictions. We however expect that in return we get feedback that can help
improve the DDL. If the DDL is used for commercial purposes we hope that the authors
drop us a note and possibly give credit where credit is due &amp;#8211; this would help
in popularizing the DDL. You are however not required to do any of these and are free
to use the DDL without any acknowledgements at all. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Also a console program is available which can be used
to test-run DDL scripts that you are developing. This is also available in source
form as an example of hosting the DDL. The site also has tutorial material about the
DDL console as well as documentation about the language, API, internal algorithms
and such. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Present
and Future:&lt;/b&gt; The DDL in its .Net avatar is presently in Beta 1 status and is the
work of two people. We believe that the idea of a generally useful DDL system has
substance and are hoping to work towards it. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoCommentText style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-bidi-font-size: 12.0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;For future development we are hoping to strengthen
to the DDL language so that the language can be used to express data formats that
are currently not expressible or are hard to express. Also plans are underway for
a compiler for the DDL language. The compiler is expected to take a .ddl file as input
and generate a .net assembly as output that will be code streamlined for your ddl
script, rather than be a general purpose ddl interpreter. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;We are hoping to build a community around the DDL and
would like to invite you to join the DDL development project. Inputs for future design
aspects, known issues etc would be appreciated. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The DDL project homepage is &lt;/font&gt;&lt;a href="http://ddl.sscli.net/"&gt;&lt;font face=Arial&gt;http://ddl.sscli.net&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; .&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Contact us: spark at sscli dot net, dolly at sscli
dot net.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face=Arial color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;(Download the &lt;a href="content/binary/DotNetDevJ.article-drawings-samples.zip"&gt;article
and related code sample here&lt;/a&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;The homepage for the
DDL project remains &lt;a href="http://ddl.sscli.net/"&gt;http://ddl.sscli.net&lt;/a&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;You may also want to
visit:&lt;/span&gt;&lt;/i&gt;&lt;font face=Arial color=#000000&gt; &lt;/font&gt;&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;a href="http://www.thinkingms.com/pensieve/homepage/work/system.ddl/index.htm"&gt;http://www.thinkingms.com/pensieve/homepage/work/system.ddl/index.htm&lt;/a&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;And &lt;a href="http://www34.brinkster.com/mpooja/work/Other/ddl/index.htm"&gt;http://www34.brinkster.com/mpooja/work/Other/ddl/index.htm&lt;/a&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;A complete description
of the language is available at &lt;a href="http://www34.brinkster.com/mpooja/work/Other/ddl/html/DDL-Language.htm"&gt;http://www34.brinkster.com/mpooja/work/Other/ddl/html/DDL-Language.htm&lt;/a&gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;Please give us feedback
about the language and what you would like to see implemented. One of the plans we
have for the future is a compiler for the DDL &amp;#8211; this has been postponed because
various other projects kept getting in the way.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=9c1c7164-5655-439c-9d3f-6bef419c1b25" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,9c1c7164-5655-439c-9d3f-6bef419c1b25.aspx</comments>
      <category>DDL</category>
      <category>Languages</category>
      <category>Programming</category>
      <category>Zeitgeist</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=61e2f23a-9c84-4188-a924-ad0cf4fe576d</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,61e2f23a-9c84-4188-a924-ad0cf4fe576d.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,61e2f23a-9c84-4188-a924-ad0cf4fe576d.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=61e2f23a-9c84-4188-a924-ad0cf4fe576d</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>Scheme Macros and Quotes</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,61e2f23a-9c84-4188-a924-ad0cf4fe576d.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/06/23/SchemeMacrosAndQuotes.aspx</link>
      <pubDate>Wed, 23 Jun 2004 13:44:10 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;Almost
every macro demonstrates a flaw&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;in the programming
language,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;in the program,
or in the programmer. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;-
Bjarne Stroustrup&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;I find it unbearably
restrictive&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;to program in
languages without macros ...&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;-
Paul Graham&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It took me some good time today getting my mind around
macros in scheme. The discussion in Dorai Sitaram&amp;#8217;s book is a not very descriptive.
I had a look at Prof Kent Dybvig&amp;#8217;s chapter about syntax and figured that that
is something I want to look at only later. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;However after a bit of mucking up I think this would
work. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(require (lib "defmacro.ss"))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(define-macro let* (lambda (args
. code)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(if
(null? args)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;`(begin
,@code)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;`(let 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;,(list
(car args))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let* 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;,(if
(null? (cdr args))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(cdr
args))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;,@code)))))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;(display 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(let* 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;((a
2)(b (+ a 10))) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(+
a b)))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face=Arial color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Thinking in scheme needs some getting used to. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=61e2f23a-9c84-4188-a924-ad0cf4fe576d" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,61e2f23a-9c84-4188-a924-ad0cf4fe576d.aspx</comments>
      <category>Languages</category>
      <category>Mish Mash</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=563f6495-6cb6-4af8-9a2c-123036436a34</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,563f6495-6cb6-4af8-9a2c-123036436a34.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,563f6495-6cb6-4af8-9a2c-123036436a34.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=563f6495-6cb6-4af8-9a2c-123036436a34</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <title>Model of Computation : Ruby</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,563f6495-6cb6-4af8-9a2c-123036436a34.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/06/19/ModelOfComputationRuby.aspx</link>
      <pubDate>Sat, 19 Jun 2004 07:50:25 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A few days back I found what seemed to be a book about
Ruby. This was being discussed on the Ruby mailing list. It&amp;#8217;s called &amp;#8220;A
Little Ruby&amp;#8221; or more precisely &lt;b&gt;&amp;#8220;A Little Ruby. A Lot of Objects&amp;#8221;&lt;/b&gt;.
You can find it here:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://web.archive.org/web/20030618203059/visibleworkings.com/little-ruby/"&gt;&lt;font face=Arial&gt;http://web.archive.org/web/20030618203059/visibleworkings.com/little-ruby/&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;(Someday it will be available here: &lt;/font&gt;&lt;a href="http://www.visibleworkings.com/little-ruby/"&gt;&lt;font face=Arial&gt;http://www.visibleworkings.com/little-ruby/&lt;/font&gt;&lt;/a&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt; )&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Instead of writing the whole thing myself or copy paste
it, I ask you to simply go read the book. That is my blog entry for the day.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The &amp;#8220;Little Ruby&amp;#8221; book is a conversation
between two people where some sublime ideas about the design philosophy of the Ruby
language are discussed. The book itself is a pleasure to read and more importantly,
to think about. (It is an incomplete book, only 3 chapters &amp;#8211; the author Brain
Marick said on the Ruby list that he hopes to complete it sometime).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;
&lt;st1:City&gt;
&lt;st1:place&gt;Reading&lt;/st1:place&gt;
&lt;/st1:City&gt;
&amp;#8220;Little Ruby&amp;#8221; put in a phrase in my thinking &amp;#8211; &lt;b&gt;&amp;#8220;Model of
Computation&amp;#8221;, &lt;/b&gt;I don&amp;#8217;t know if this sounds sober, but I think this
is what I am really looking for. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In all my tinkering around languages, compilers, runtimes
and other things &amp;#8211; I am looking for a Model of Computation, a fundamental set
of programmatic thought abstractions that are beautiful and can encompass various
forms of programming. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The Little Ruby book talks about a model of computation
where all computation is simply built around the idea of passing messages to objects.
It is a simple concrete idea with which the rest of the Ruby world is built (apart
of syntactic sugar). I don&amp;#8217;t know if you are used to thinking in this way &amp;#8211;
but it is a powerful form of thought.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Let me quote from one of the conversation toward the
end of the third chapter (the last chapter that is written so far):&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;#8220;A language that provides lots of features&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;will always be missing that one feature you&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;need.&amp;#8221;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&amp;#8220;But a language that chooses the right&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;simple rules for you to combine lets you&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;build the features you need.&amp;#8221;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is the basic idea of composition &amp;#8211; small
integral units that compose to produce powerful behavioral entities. Have you ever
thought why a unix command shell guy never really thought much of a Win/Dos user &amp;#8211;
because somewhere the way the shell forces you to thinking terms of composition of
small do-one-thing-well tools and create powerful meta-tools, is a greater thought
pattern. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You might have heard this being said about tools in
the old unix culture (I say &amp;#8216;old&amp;#8217; because I have different opinions of
&amp;#8216;unix&amp;#8217; culture as it is now)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;"This is the Unix philosophy. Write programs
that do one thing and do it well. Write programs to work together. Write programs
to handle text streams, because that is a universal interface." 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;--Doug McIlroy&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The &amp;#8220;Little Ruby&amp;#8221; book is inspired by the
old book &amp;#8220;The Little LISPer&amp;#8221;. Something that is now on my reading list
&amp;#8211; I can&amp;#8217;t seem to get a copy of this anywhere. The present edition of
the book is called &amp;#8220;The Little Schemer&amp;#8221;. The book is co written by &lt;/font&gt;&lt;a href="http://www.cs.indiana.edu/~dfried/"&gt;&lt;font face=Arial&gt;Prof
Daniel P Friedman of Indiana University&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; and
Prof Matthias Felleisen of 
&lt;st1:place&gt;
&lt;st1:PlaceName&gt;Rice&lt;/st1:PlaceName&gt;
&lt;st1:PlaceType&gt;University&lt;/st1:PlaceType&gt;
&lt;/st1:place&gt;
. The Little Schemer discusses a different model of computation from what the &amp;#8220;Little
Ruby&amp;#8221; describes. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I did not know this then, but sometime last year I
was in email correspondence with Prof Friedman. That time, had I known that he is
author of a respected LISP text book, I might have been frightened off the prospect
of asking this - &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;but in one of the mails
I had asked &amp;#8220;why Lisp?&amp;#8221;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Roshan,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;The most fundamental building block of computation
is composition. If the language does not support composition in a trivial way, then
I have no use for it.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ML, Haskell, LISP,
and Scheme each give a kind of composition.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Composition
is the building block of Category Theory, which is a unifying tool that helps clarify
much of mathematics. and logic.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;So, thinking
that it would be okay to use a language that does not support composition is impossible
for me.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;(I quote this here presently without his permission,
I believe he would be ok though). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I didn&amp;#8217;t understand him then. But now after a
year, I think I am closer to understanding him. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What would a unified model of computation be? Can such
a thing exist? Can we think of all computation using a set of minimal and powerful
abstraction such that every other form of computation can be built out of it. Can
this be one that is easy and fun to use that we could interact with this &lt;i&gt;force &lt;/i&gt;on
a day to day basis. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;And what forms the underlying foundation for computation
then might also form the underlying basis for other systems of organized thought as
well. This is like the dream of Grand Unified Field Theory in physics. Can something
like that exist in the computational systems as well? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I don&amp;#8217;t know enough to guess. But however I believe
that as long we keep pursuing computing in a way that is fun and simple, we are probably
on the right track. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;To end this entry I want to quote from the preface
of the little ruby:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Welcome to my little book. In it, my goal
is to teach you a way to think about computation, to show you how far you can take
a simple idea: that all computation consists of sending messages to objects. Object-oriented
programming is no longer unusual, but taking it to the extreme - making everything
an object - is still supported by only a few programming languages.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Can I justify this book in practical terms?
Will reading it make you a better programmer, even if you never use "call with current
continuation" or indulge in "metaclass hackery"? I think it might, but perhaps only
if you're the sort of person who would read this sort of book even if it had no practical
value.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;The real reason for reading this book is that
the ideas in it are neat. There's an intellectual heritage here, a history of people
building idea upon idea. It's an academic heritage, but not in the fussy sense. It's
more a joyous heritage of tinkerers, of people buttonholing their friends and saying,
"You know, if I take that and think about it like this, look what I can do!"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;As a closing note, sometime last year I was looking
to do research under someone working with the SSCLI code base and work on virtual
machines and runtimes. I wanted to do my Masters. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;At that time the best way I could describe what I wanted
to do was to say that I was looking runtimes and virtual machines research with a
specific interest in SSCLI. Now, maybe I can describe myself a little better. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The only way I could think of doing this that time
was to ask around in online forums and mailing lists about universities doing work
with Rotor. That accompanied by a barrage of mails to everyone who I thought might
know, or point me in the right direction. One name that came up was of &lt;/font&gt;&lt;a href="http://st-www.cs.uiuc.edu/users/johnson/index.html"&gt;&lt;font face=Arial&gt;Prof
Ralf Johnson of UIUC&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. Right now I was looking
for Brian Marick (author of little ruby) on Google, Brian is research student doing
his PhD under Prof. Johnson.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=563f6495-6cb6-4af8-9a2c-123036436a34" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,563f6495-6cb6-4af8-9a2c-123036436a34.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
      <category>Ruby</category>
      <category>Zeitgeist</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=8bafabcf-5ca4-41b7-a1a0-94a876a16e34</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,8bafabcf-5ca4-41b7-a1a0-94a876a16e34.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,8bafabcf-5ca4-41b7-a1a0-94a876a16e34.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=8bafabcf-5ca4-41b7-a1a0-94a876a16e34</wfw:commentRss>
      <title>Msh/Monad: Cmdlet parameter binding</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,8bafabcf-5ca4-41b7-a1a0-94a876a16e34.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/06/12/MshMonadCmdletParameterBinding.aspx</link>
      <pubDate>Sat, 12 Jun 2004 11:54:31 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;With some things cleared up and some ground work done,
here is one of the first the things I want to talk about in Monad &amp;#8211; the new
Microsoft Command Shell(msh).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In my first article I talked about &amp;#8216;cmdlets&amp;#8217;
and that they return .Net objects. Here is one other smart and subtle thing they did
with Monad &amp;#8211; Parameters to cmdlets come not only on the command line but can
also come from objects in the input object pipeline. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Some basic stuff on cmdlets and parameters which might
help set the stage for understanding things. A command-let can define fields/member
variables as part of the command let class. These fields can then be decorated by
attributes so that they can be treated as parameters to the commandlet. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In code it actually looks like this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;[CmdletDeclaration( "demo", "cmdlet"
)]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;strong&gt;public class HelloWorld
: Cmdlet&lt;o:p&gt;&lt;/o:p&gt;
&lt;/strong&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;strong&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/strong&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[ParsingPromptString("Enter
a string to echo: " )]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[ParsingParameterMapping(0)]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[ParsingMandatoryParameter]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;[ParsingAllowPipelineInput]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;strong&gt;private
string message;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/strong&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(This snippet is a modified version of code
from the beta documentation)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now this might look a little over decorated with attributes,
but the thing I want you to notice is that that is a member called &amp;#8216;message&amp;#8217;
which simply has a few attributes applied. Applying those attributes causes &amp;#8216;message&amp;#8217;
of type System.String to be a parameter required for our command let. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Unlike traditional command line exes, the responsibility
of parsing the command line options and assigning them to internal variables is not
the responsibility of the program but is automatically done for you by the Monad shell. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Which is to say that by the time code that you write
in the cmdlet is executed, values are already assigned to the parameter variables
by the shell. (Not strictly, but almost).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The shell can let you assign parameter values either
by specifying them at a certain postion in the command line &amp;#8211; for example argv[1]
will be the value for &amp;#8216;message&amp;#8217;, argv[2] will be the value for something
else and so on. Or the shell lets you&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;specify
the parameter name and then the value &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&amp;gt; demo-cmdlet &amp;#8211;message
&amp;#8220;hello world&amp;#8221; -&amp;lt; parameter name &amp;gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;
value &amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The other good thing (which is new and what this log
entry was about) is that the value for a parameter can be extracted from an object
on the pipeline if the object has a field/member of the same name. (The types have
to be consistent)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So if I have a command let that generates an object
of type foobar that has a member of name &amp;#8216;message&amp;#8217;, I can pipe the output
to the commandlet that required a parameter of name &amp;#8216;message&amp;#8217; and it would
all work.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&amp;gt; create-foobar | demo-cmdlet&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Would create foorbar instances that get piped to demo-cmdlet
which uses the &amp;#8216;foobar.message&amp;#8217; as its message parameter.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Where would this be used? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;For an example there is a command-let called &amp;#8216;get-process&amp;#8217;.
It lists the running processes on the system. To be more precise it returns a collection
of process instances which get standard formatted to the console. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;MSH 5 C:/&amp;gt;get-process&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;ProcessName&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Id&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;HandleCount&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;WorkingSet&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;-----------&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;--&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;-----------&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;----------&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;CcmExec&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;288&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;480&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;14008320&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;cmd&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;804&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;22&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;1421312&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;csrss&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;464&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;669&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;4743168&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;dfssvc&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;316&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;70&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;3260416&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;DWRCS&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;1444&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;44&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;2560000&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;explorer&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;3520&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;366&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;20926464&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;FrameworkService&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;1544&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;303&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;9367552&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;Idle&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;16384&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Similarly to see all the instances of notepad that
are running I would simply say&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;MSH 16 C:/&amp;gt;get-process
note*&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;ProcessName&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Id&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;HandleCount&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;WorkingSet&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;-----------&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;--&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;-----------&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;----------&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;notepad&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;3912&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;16&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;1912832&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;notepad&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;4044&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;16&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;1912832&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;notepad&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;3056&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;16&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;1912832&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now there is a cmdlet called stop-process which can
terminate a process if you pass it the process id as a parameter. The parameter name
that stop-process expects is called &amp;#8216;Id&amp;#8217;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;MSH 11 C:/&amp;gt;command
stop-process&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;Command: stop-process&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;Command Parameters:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Id&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;:
Int32[]&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;:
Optional&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ProcessName&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;:
String[]&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;:
Optional&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So with all the earlier talk you can conclude that
if I simply wanted to kill all the instances of notepad that are running I could type&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;MSH 11 C:/&amp;gt;get-process note*
| stop-process&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 8pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now isn&amp;#8217;t that clean? Just to add a bit of garnishing
to that, Monad defines &amp;#8216;ps&amp;#8217; as an alias to get-process and &amp;#8216;kill&amp;#8217;
as an alias to &amp;#8216;stop-process&amp;#8217;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So now you can say &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;MSH 11 C:/&amp;gt;ps note* | kill&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Cool? This works on Monad today.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;strong&gt;Prev:&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;a href="/CommentView,guid,1afc98ec-393f-4631-9cb4-d32e63a9fe15.aspx"&gt;Introductory
entry about Monad&lt;/a&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;strong&gt;Next:&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#004183&gt;&lt;a class=TitleLinkStyle href="/CommentView,guid,1d435872-db18-4250-9c65-f3005149b2fb.aspx"&gt;ObjShell:
A precursor of Monad? &lt;/a&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=8bafabcf-5ca4-41b7-a1a0-94a876a16e34" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,8bafabcf-5ca4-41b7-a1a0-94a876a16e34.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=1afc98ec-393f-4631-9cb4-d32e63a9fe15</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,1afc98ec-393f-4631-9cb4-d32e63a9fe15.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,1afc98ec-393f-4631-9cb4-d32e63a9fe15.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=1afc98ec-393f-4631-9cb4-d32e63a9fe15</wfw:commentRss>
      <title>Microsoft Command Shell : msh/Monad</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,1afc98ec-393f-4631-9cb4-d32e63a9fe15.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/06/10/MicrosoftCommandShellMshMonad.aspx</link>
      <pubDate>Thu, 10 Jun 2004 11:25:24 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;For a little less than a week now, I have been playing
with the March build of the new command shell that Microsoft will be releasing in
the Longhorn time frame. Being a command line/console enthusiast, I find this rather
exciting news. Indeed it has been years since MS actually did anything significant
to better its command shell &amp;#8211; Monad is it. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I don&amp;#8217;t really know how much I am allowed to
talk about Monad itself because of some NDA material, but if you look around on the
net you will find a pretty much a lot. One thing about the way the NDA was explained
to me recently was that they said &amp;#8211; if you can find the material on the web
then assume its not under NDA !! (whatever .. )&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One thing that Monad does differently from other command
shells, be it cmd.exe or bash/ksh/csh is that Monad is centered around the idea of
an object pipeline. Let me explain:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Traditionally one of the ways of defining a console
application is to say that it is an application that was access to three streams by
default &amp;#8211; usually numbered 0,1 and 2 and called the stdin, stdout and stderr.
These are text streams. This means that you can read/write text data from these streams. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When you pipe the output of one program to another
program on the command line, what you are basically doing is that you are &amp;#8216;connecting&amp;#8217;
the stdout of the first process to the stdin of the second process. So text that it
is outputted from one process is treated as input text for the next process. This
is known territory. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;For a long time I appreciated the beauty and simplicity
of this approach &amp;#8211; what could be better, well Monad could be. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Monad provides &amp;#8216;applications&amp;#8217; (I use this
term loosely here) on the shell with three streams &amp;#8211; but these are not text
streams but object streams. Applications that read and write objects in the object
pipeline are not traditional processes but are called &amp;#8216;commandlets&amp;#8217;. A
cmdlet is actually just a .Net class that is decorated by certain attributes (etc
etc).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When cmdlets are executed from the msh command line,
these classes are instantiated and are given access to the object streams. So one
cmdlet writes objects to the output object stream which is read in through the input
object stream of the other commandlet. In essence the same idea of piping as with
text streams, but this time what passes around are full blown .Net objects. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Giving this idea a little thought, you will realize
that this makes for much richer shell programming. Like for example a lot of time
effort is spent in shell programming (traditionally a unix forte) is scrapping out
meaningful values from the output of other commands. Even entire languages (awk) have
been created largely for this kind of text scrapping. For example if you do a ps &amp;#8211;ax,
then you really need to cut out (literally) the columns of text where the process
id falls so that you can automatically call a kill command with it. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This kind of difficulty completely disappears with
Monad simply because the cmdlets down the object stream get full objects and so they
can examine the fields of these objects for the parameters they want. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Of course this kind of functionality would have been
near impossible in the pre .Net era because there was no understandable concept of
a &amp;#8216;type&amp;#8217; that was applicable across languages. The shell being purely
a .Net shell the command-lets can talk .Net and can thus consume any .net type. (Remember
this is one of the basic tenets of the .Net platform - &lt;/font&gt;&lt;a href="http://www.oreilly.com/catalog/sscliess/chapter/ch01.pdf"&gt;&lt;font face=Arial&gt;that
its tries to provide a level playing field for languages to interact&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When a command let returns a set of types and there
are no more command lets in the pipeline to consume to objects then the objects are
formatted in some standard way to the console. What that means is that if we have
a command called &amp;#8216;ps&amp;#8217; it would be expected to return a collection of objects
each of which represent a running process. Now if at the console I type simply &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&amp;gt; ps &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;then there are no more commandlets that receive the
process objects returned by &amp;#8216;ps&amp;#8217;. These objects are formatted in a standard
manner to the console so that user can see them. Nice? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Monad has really appealed to me in the short time I
have spent with it. Traditional shells like bash may have some catching up to do in
the light of power like this. Of course Monad is presently at a nascent stage. However
for an early pre-beta, Monad is already a very sophisticated and elegant system. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I don&amp;#8217;t know if I have crashed any NDAs already.
I need to check up on that before I continue. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&lt;strong&gt;Next: &lt;/strong&gt;
&lt;br&gt;
&lt;a href="/CommentView,guid,8bafabcf-5ca4-41b7-a1a0-94a876a16e34.aspx"&gt;Cmdlet parameter
binding in Monad&amp;nbsp;&lt;/a&gt;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&lt;strong&gt;Other:&lt;/strong&gt;
&lt;br&gt;
&lt;a href="/CommentView,guid,96c11f79-78fb-4c7e-aeaa-80e1631b52b8.aspx"&gt;Some of my ranting
about NDA&lt;/a&gt;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&lt;a href="/CommentView,guid,c87198be-1739-4156-a53b-25c92984ed94.aspx"&gt;Clarifications
on NDA related issues about Monad&lt;/a&gt;
&lt;br&gt;
&lt;a href="http://dolly.thinkingms.com/CommentView,guid,486fb9c8-719c-4cc8-9386-d0f50aeb354f.aspx"&gt;Pooja
on deployment of Monad on 'unsupported' OSes&lt;/a&gt;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&lt;/font&gt;
&lt;/o:p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=1afc98ec-393f-4631-9cb4-d32e63a9fe15" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,1afc98ec-393f-4631-9cb4-d32e63a9fe15.aspx</comments>
      <category>Languages</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=92e51a8a-4d8d-4401-beb2-8b68a019d4bb</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,92e51a8a-4d8d-4401-beb2-8b68a019d4bb.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,92e51a8a-4d8d-4401-beb2-8b68a019d4bb.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=92e51a8a-4d8d-4401-beb2-8b68a019d4bb</wfw:commentRss>
      <title>CLR 2.0 Closures and Environment classes that capture arity</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,92e51a8a-4d8d-4401-beb2-8b68a019d4bb.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/06/03/CLR20ClosuresAndEnvironmentClassesThatCaptureArity.aspx</link>
      <pubDate>Thu, 03 Jun 2004 05:58:34 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=15"&gt;&lt;font face=Arial&gt;Antonio
has a post&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; about generalizing environment
classes (that capture state of a closure) with using generic types, such that the
class itself captures only the arity of the environment. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;To quote:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=15"&gt;&lt;font face=Arial&gt;http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=15&lt;/font&gt;&lt;/a&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;In general we may think that the compiler
generates several environment classes, for the needed arities; for instance:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;class Environment3&amp;lt;A, B, C&amp;gt;
{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;A
a;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;B
b;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;C
c;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;There is one issue that I can think of, off the top
of my head &amp;#8211; the CLR has a an excellent approach to generics (among the best
I have seen) and is well described in Don Syme&amp;#8217;s paper here:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;The Design and Implementation of Generics
for the .NET Common Language Runtime&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;a href="http://research.microsoft.com/projects/clrgen/generics.pdf"&gt;&lt;span style="FONT-WEIGHT: normal"&gt;&lt;font face=Arial&gt;http://research.microsoft.com/projects/clrgen/generics.pdf&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;the thing about CLR generics is that they are very
efficient for all reference types, because for reference types there is no specialization
of templating behavior (as with classical c++ style generics). All reference types
use the class definition during runtime. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;However value types cause the runtime to generate specialized
classes to handle type of a value type that is used is a templated entity. Classes
definitions are shared by value types only when they share the same foot print with
respect to the GC.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So it would be better is compiler actually generated
specialized classes to hold environment state whenever is knows that the types the
environment needs to hold are value types. This simply provides for a performance
benefit, because the specialization of the class will not happen at runtime, instead
will be done at compile time. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Antonio also discusses a private member access issue
&amp;#8211; again I don&amp;#8217;t think I fully get him. Assuming the new delegate mechanism
is in place we could have classes that look like this&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;class Env&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//have
only public members&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;class Foo&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//original
method&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void
bar()&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//anonymous
compiler generated method&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void
anon_bar()&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//access
all members of Foo here&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//access
all public members of Env here&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Is there a need to make members to Env private? The
entire point of having Env is simply to act as a place holder for some values. Better
yet (I don&amp;#8217;t know if the old friend method mechanism works), but if friend decls
are possible then the anonymous method can be declared as a friend in class Env. This
does not add to the class definition in any way, it would simply allow for member
access. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You might want to look at these links to follow the
sequence of these posts &amp;#8211; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;1)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=8"&gt;&lt;font face=Arial&gt;Closures
in CLR 2.0&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;2)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="/CommentView,guid,9fe42970-09e3-44e2-a4d0-32d63139351a.aspx"&gt;&lt;font face=Arial&gt;Implementation
of Closures (Anonymous Methods) in C# 2.0 (Part 6)&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;3)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=14"&gt;&lt;font face=Arial&gt;More
on CLR 2.0 closures&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;4)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="/CommentView,guid,81e20e21-6ec6-4fed-9c89-a5b77d21aec6.aspx"&gt;&lt;font face=Arial&gt;Closure
implementation enhancement in CLR 2.0 using the new delegate mechanism&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;span style="mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;5)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=15"&gt;&lt;font face=Arial&gt;Again
on closures&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;i&gt;&lt;span style="mso-fareast-font-family: Arial; mso-bidi-font-family: Arial"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font face=Arial&gt;6)&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;i&gt;&lt;font face=Arial&gt;this
post&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/i&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=92e51a8a-4d8d-4401-beb2-8b68a019d4bb" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,92e51a8a-4d8d-4401-beb2-8b68a019d4bb.aspx</comments>
      <category>Languages</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=c08b14fd-8641-4bba-a1c6-e620145948d1</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,c08b14fd-8641-4bba-a1c6-e620145948d1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,c08b14fd-8641-4bba-a1c6-e620145948d1.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=c08b14fd-8641-4bba-a1c6-e620145948d1</wfw:commentRss>
      <title>Language Research</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,c08b14fd-8641-4bba-a1c6-e620145948d1.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/06/02/LanguageResearch.aspx</link>
      <pubDate>Wed, 02 Jun 2004 12:35:22 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is a tremendously exciting time to be thinking
about programming languages and language research. I recently I have come across a
lot of material that has made me think a lot. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Polyphonic C#&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;a href="http://research.microsoft.com/%7Enick/polyphony/"&gt;&lt;span style="FONT-WEIGHT: normal"&gt;&lt;font face=Arial&gt;http://research.microsoft.com/%7Enick/polyphony/&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;This
is a C# like language that is built for concurrency control. Amazing piece of thought
exercise there. I recommend looking at &lt;/font&gt;&lt;/font&gt;&lt;a href="http://research.microsoft.com/~nick/polyphony/modern-concurrency-abstractions-for-csharp.pdf"&gt;&lt;font face=Arial&gt;Modern
Concurrency Abstraction for C#&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Xen/X# from Microsoft Research&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;Xen basically proposes to extend the C# language
to better data handling support into the language.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://research.microsoft.com/~emeijer/Papers/XS.pdf"&gt;&lt;font face=Arial&gt;Unifying
Tables Objects and Documents&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This should give you a good idea of X#. This is by
Erik Meijer of MSR. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: black"&gt;&lt;a href="http://www.only4gurus.com/techlib/microsoft/xml2003.pdf"&gt;&lt;font face=Arial&gt;Programming
with Circles, Triangles and Rectangles&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;More &amp;#8211; interesting reading. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;C Omega 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;a href="http://research.microsoft.com/Comega/"&gt;&lt;span style="FONT-WEIGHT: normal"&gt;&lt;font face=Arial&gt;http://research.microsoft.com/Comega/&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face=Arial color=#000000&gt;A combination of Xen and Polyphonic C#. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You might want to download this ppt that discusses &lt;/font&gt;&lt;a href="content/binary/Portugal%20Comega.zip"&gt;&lt;font face=Arial&gt;C
Omega by none other than Damian Watkins of MSR.&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Groovy&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://groovy.codehaus.org/"&gt;&lt;font face=Arial&gt;http://groovy.codehaus.org/&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Groovy
is the Ruby like language for the JVM. Ruby itself takes from the power of dynamic
object oriented-ness that was so characteristic of smalltalk and whips a powerful
expressive language on it. The thing is that Groovy also builds in Xen like concepts. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You might want to download this ppt that discusses &lt;/font&gt;&lt;a href="content/binary/Groovy.zip"&gt;&lt;font face=Arial&gt;Groovy
by James Strachan&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; co-author of groovy. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Self&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://research.sun.com/self/language.html"&gt;&lt;font face=Arial&gt;http://research.sun.com/self/language.html&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;An old language from Sun Microsystems. Reading up about
self makes you appreciate the spirit of many message passing and prototypes and cloning
based pure object oriented systems. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am not mentioning functional languages here because
it is not fair to put up stuff I have no clue about. I must say this is an amazing
time to be interested in programming languages. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=c08b14fd-8641-4bba-a1c6-e620145948d1" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,c08b14fd-8641-4bba-a1c6-e620145948d1.aspx</comments>
      <category>Languages</category>
      <category>MLP (Mindless Link Propagation)</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=81e20e21-6ec6-4fed-9c89-a5b77d21aec6</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,81e20e21-6ec6-4fed-9c89-a5b77d21aec6.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,81e20e21-6ec6-4fed-9c89-a5b77d21aec6.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=81e20e21-6ec6-4fed-9c89-a5b77d21aec6</wfw:commentRss>
      <title>Closure implementation enhancement in CLR 2.0 using the new delegate mechanism</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,81e20e21-6ec6-4fed-9c89-a5b77d21aec6.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/05/28/ClosureImplementationEnhancementInCLR20UsingTheNewDelegateMechanism.aspx</link>
      <pubDate>Fri, 28 May 2004 06:16:56 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I had dropped a link to &lt;/font&gt;&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=8"&gt;&lt;font face=Arial&gt;Antonio
Cisternino&amp;#8217;s blog entry about Closure support in CLR 2.0&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; when
I was writing a description of how the &lt;/font&gt;&lt;a href="/CommentView,guid,9fe42970-09e3-44e2-a4d0-32d63139351a.aspx"&gt;&lt;font face=Arial&gt;C#
compiler (Whidbey release) implements closures&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I was completely wrong about what Antonio&amp;#8217;s blog
entry was about. For some reason, my head being so full of C# that it is, I assumed
he was talking about the how closures were implemented in C# for the Whidbey release.
Closures in the Whidbey release (Visual Studio 2005) are officially called anonymous
methods. So apologies Antonio, I had missed the point.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;That said, what Antonio was referring to was a subtle
change in the implementation of the delegates in CLR 2.0 so that the future CLR can
be better used to implement closures and support functional languages and constructs.
I exchanged some mails with him and I think I get what he was talking about.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Before I go any further I would recommend you reading
Antonio&amp;#8217;s original entry&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=8"&gt;&lt;font face=Arial&gt;Closures
in CLR 2.0&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;, my entry about the &lt;/font&gt;&lt;a href="/CommentView,guid,9fe42970-09e3-44e2-a4d0-32d63139351a.aspx"&gt;&lt;font face=Arial&gt;implementation
of closures in C# 2.0&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; using delegates as
they are available in CLR 1.x and Antonio&amp;#8217;s follow-up entry that speaks of the
distinguishing aspect of the new delegate implementation: &lt;/font&gt;&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=14"&gt;&lt;font face=Arial&gt;More
about Closures in CLR 2.0&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The following are derived from mail exchanges with
Antonio. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A delegate can be thought of as an entity that holds
a pointer to a function and optionally a reference to the object for which the function
is supposed to be an instance function. In CLR 2.0 a simple and subtle change has
taken place where in the constraint that the instance pointer has to refer to the
object for which the function pointer is member function, has been removed. The function
pointer and the object reference don&amp;#8217;t have to be related to each other. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In functional languages delegates are often implemented
by having a pointer to a function which is the block of code that belongs to the closure
and a pointer to an instance of the environment. The environment is the entity that
holds the state for the code in the closure block. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In C# 2.0 the environment object is implemented by
creating a class for &lt;b&gt;every&lt;/b&gt; function that wraps a closure and shares state with
it. Such a class is generated name-mangled as __LocalsDisplayClassXXX in C# 2.0. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The code that is part of the closure is now part of
the environment class. When a closure is created an instance of the environment class
is created and a delegate is returned to the instance and its member function that
wraps the closure code. This is what could be done with CLR 1.x delegates as the function
had to be a member of the environment class. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;With CLR 2.0 delegates, what the compiler writers now
have the option of doing is that they can generate a common environment class for
all functions that wrap closures that need to capture similar information about its
environment. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is an example and some notes courtesy of Antonio:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Closures in functional programming languages
are often implemented with pointers pairs (env, func) where env is the pointer to
the environment of the closure, and func is a pointer to a function whose first argument
will be env.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;With CLR 1.0 this cannot be achieved because
delegates are pairs but with an additional constraint: func should be declared in
the class of env. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;The problem with this additional constraint
on delegates is that you tend to define a class for each closure you make. In a functional
programming language you'll pay a significant overhead because for each closure you
have to introduce a private class with the environment and the code.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Besides removing that constraint (as it has
been done in CLR 2.0) you can define a class with plenty of static methods, one per
closure and define a type for each possible environment. This reduces the number of
types you need to have. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;For instance:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;void foo() {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;string
s;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;Cmd
d = { Console.WriteLine(s); }&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;//...&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;void baz() {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;string
s;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;Cmd
d = { Console.WriteLine("Hello {0}", s); }&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;//...&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;The current compiler generates two classes
both having a single int field.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;With CLR 2.0 the compiler could use a single
class as follows:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;class Env_String {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;string
f;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;void f(Env_String env) { Console.WriteLine(env.s);
}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;void g(Env_String env) { Console.WriteLine("Hello
{0}", env.s); }&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;void foo {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;Env_String
env = new Env_String();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;Cmd
d = (Cmd)Delegate.CreateDelegate(typeof(Cmd), env,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;GetType().GetMethod("f"));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;//...&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;void baz {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;Env_String
env = new Env_String();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;Cmd
d = (Cmd)Delegate.CreateDelegate(typeof(Cmd), env,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;GetType().GetMethod("g"));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;//...&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: teal"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In the above case the environment class need be only
one, as in both the closures, the environment needs to capture the state of only a
string variable. The environment class itself can be kept free of the closure specific
code and the methods that are generated for the closure can be placed in the class
that the original enclosing method was a part of. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This subtle thing had escaped my thinking for sometime.
I guess when you are doing your PhD with a university that hosts one of the worlds
largest .Net user-groups and are working with matters related to MSR Cambridge, you
tend to pick up subtle things a lot easier. :-)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;There is one thing that has me thinking is about the
implementation of closures in the case of closures being defined inside instance methods.
If you refer &lt;/font&gt;&lt;a href="/CommentView,guid,9fe42970-09e3-44e2-a4d0-32d63139351a.aspx"&gt;&lt;font face=Arial&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;,
I show a screen shot of an ildasm of that case. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When an instance function is being used the environment
will have to have a &amp;#8216;this&amp;#8217; pointer member that the closure block can access
to access any class data members. When the C# compiler is generating one class per
function wrapping a closure the &amp;#8216;this&amp;#8217; can be statically typed to the
type of the class that contained the parent method. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;
&lt;v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"&gt;
&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;
&lt;v:formulas&gt;
&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;
&lt;/v:formulas&gt;
&lt;v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"&gt;&lt;/v:path&gt;
&lt;o:lock aspectratio="t" v:ext="edit"&gt;
&lt;img height=238 src="content/binary/cs_closure_5.gif" width=346 border=0&gt;
&lt;/o:lock&gt;
&lt;/v:shapetype&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If the environment class is to be shared across multiple
classes that implement closures, then what will be the type of the &amp;#8216;this&amp;#8217;
pointer? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am guessing here, but I would expect that they might
choose to create the environment class as generic class that is type independent on
the &amp;#8216;this&amp;#8217; pointer. Do you think that sounds right? What are the possible
fallouts with that approach? Generic environment classes. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;As a matter of fact when you dive into the possibility
that generics opens up, it&amp;#8217;s rather interesting. We could have the entire environment
as a class that contains templated / generic types for every reference type member.
This might be efficient to implement because the implementation of generics in the
.Net framework does not involve specialization of the runtime class for reference
types. Even for value types, I believe it does optimizations to avoid class duplication
if the value types have similar footprints as far as the GC is concerned. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One thing is for sure, the future looks interesting
for functional and dynamic languages leveraging the CLR. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Among other things, I am looking forward to the MVP
India summit that should be happening this weekend 28&lt;sup&gt;th&lt;/sup&gt; May to 31&lt;sup&gt;st&lt;/sup&gt; May. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=81e20e21-6ec6-4fed-9c89-a5b77d21aec6" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,81e20e21-6ec6-4fed-9c89-a5b77d21aec6.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=9fe42970-09e3-44e2-a4d0-32d63139351a</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,9fe42970-09e3-44e2-a4d0-32d63139351a.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,9fe42970-09e3-44e2-a4d0-32d63139351a.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=9fe42970-09e3-44e2-a4d0-32d63139351a</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <title>Implementation of Closures (Anonymous Methods) in C# 2.0 (Part 6)</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,9fe42970-09e3-44e2-a4d0-32d63139351a.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/05/22/ImplementationOfClosuresAnonymousMethodsInC20Part6.aspx</link>
      <pubDate>Sat, 22 May 2004 06:10:56 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;C#
2.0 has support for closures. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This article discusses the implementation of the closures
in the C# language and how this has been done using pure compiler magic without any
CLR changes. I had previously mentioned C# closures in an earlier blog entry and had
linked to Antonio Cisternino&amp;#8217;s blog entry:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=8&amp;amp;Source=http://rotor.di.unipi.it/cisterni/Lists/My%2520Blog/AllItems.aspx"&gt;&lt;font face=Arial&gt;Closures
in CLR 2.0&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is an interesting entry and worth a read. Unfortunately,
IMO, Mr. Cisternino&amp;#8217;s entry is a not correctly titled. The support for closures
is a C# only thing not a CLR level addition. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I intend to start off where his blog entry ends. Here
I shall look into how it is done. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Features such as closures have been taken to legendary
fame in languages like scheme and ruby. Recent language developments like &lt;/font&gt;&lt;a href="/CommentView,guid,8db48b27-c3c9-4782-a595-7656e63305b1.aspx"&gt;&lt;font face=Arial&gt;Groovy
also ship with closure constructs&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Microsoft, for some reason, has been calling the new
feature of the language as anonymous methods. I don&amp;#8217;t know why this feature
hasn&amp;#8217;t been publicly been spoken of as closure or lambda support in the C# language.
Maybe there are subtle differences in the theoretical definition of closures and what
the C# language achieves. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;That said &amp;#8211; let&amp;#8217;s jump into the matter. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is C# code that shows off a closure:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Code Showing One Anonymous Method / Closure
that shares variables with its scope 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;//closure.cs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;//Compile: csc closure.cs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;using System;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;class CMain&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;delegate
void Closure(int n);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
Closure CreateClosure()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
c = 0;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
delegate(int n) {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine("Closure:
n = {0}, c = {1}",n,c++);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;};&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;span style="COLOR: green"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
void &lt;/span&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;
&lt;st1:place&gt;
&lt;span style="COLOR: green"&gt;Main&lt;/span&gt;
&lt;/st1:place&gt;
&lt;span style="COLOR: green"&gt;()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Closure
c1 = CreateClosure();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Closure
c2 = CreateClosure();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c1(1);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c1(1);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c1(1);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c2(2);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c2(2);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c2(2);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This code is very similar to the &lt;/font&gt;&lt;a href="/CommentView,guid,8db48b27-c3c9-4782-a595-7656e63305b1.aspx"&gt;&lt;font face=Arial&gt;groovy
snippet I had posted sometime back&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. When
executed, this is the output:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;&amp;gt; closure.exe&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;Closure: n = 1, c = 0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;Closure: n = 1, c = 1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;Closure: n = 1, c = 2&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;Closure: n = 2, c = 0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;Closure: n = 2, c = 1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face="Courier New"&gt;Closure: n = 2, c = 2&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you don&amp;#8217;t know what closures are about, the
easiest way to appreciate them is to take a careful look at the C# code above. Notice
the function CreateClosure() is returning a delegate to a block of code &lt;i&gt;that is
part of the function itself&lt;/i&gt;. (Normally you would create a delegate to a function).
If you don&amp;#8217;t understand what a delegate is, let it be. What you need to understand
is that the function &lt;i&gt;returns a block of code&lt;/i&gt; that is a part of the function. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The block of code accepts an integer parameter. Also,
you will notice that the local variable of the function (variable &amp;#8216;c&amp;#8217;)
is being used in the code block. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When the block of code is returned to the caller (in
this case main), the 
&lt;st1:place&gt;Main&lt;/st1:place&gt;
() can invoke the variable that represents the block of code, causing the code to
run. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Once upon a time you could create a delegate to an
independent function only and not to a code block within a function. A delegate to
a function had to have the same signature as the function. The delegate could be thought
of as an old C style function pointer. When the delegate is invoked, the function
pointed to is called. Delegates came with the additional merit that they were type
safe function pointers &amp;#8211; most people did not think much more than that about
delegates. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now it is a little different. While the anonymous method
within the CreateClosure() method actually looks like it simply has a nested function
that does not have a name explicitly provided its not that simple. You might venture
to guess that the compiler actually goes on to create a new method (by extracting
this code block) and simply creates a delegate to the new function, the same way delegates
once used to behave. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;However, notice that the code block uses variable &amp;#8216;c&amp;#8217;
that is defined locally to the enclosing function. If this code block is going to
be carved out of the enclosing function, how can it access variable &amp;#8216;c&amp;#8217;?
Better yet, take a closer look at the output. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It looks like a closure returned from a call to CreateClosure()
is seems to remember its value of the variable &amp;#8216;c&amp;#8217;. Some how, the &lt;i&gt;state&lt;/i&gt; of
the function CreateClosure() is captured in the delegate/closure that it returns.
So much so, that the state of two invocations of CreateClosure() seemed to be maintained
independent of each other. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is in violation of the way simple C like functions
work, where the function state is stored on the stack and the functions stack frame
is torn down from the stack and state is lost when the functions return. (Refer &amp;#8216;&lt;/font&gt;&lt;a href="/CommentView,guid,d355277d-a942-4a50-aa03-d68413fd459c.aspx"&gt;&lt;font face=Arial&gt;The
Big Deal about Iterators&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;&amp;#8217;)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Functions that return closures seemed maintain state
even after they have returned. The closure object is maintains a reference to that
state. This requirement of maintaining is similar to the implementation of iterators
(if you give it some thought).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Implementation&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is what our closure.cs looks like under ILDASM. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;
&lt;v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;
&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;
&lt;v:formulas&gt;
&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;
&lt;/v:formulas&gt;
&lt;v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"&gt;&lt;/v:path&gt;
&lt;o:lock v:ext="edit" aspectratio="t"&gt;
&lt;img height=304 src="content/binary/cs_closure_1.gif" width=589 border=0&gt;
&lt;/o:lock&gt;
&lt;/v:shapetype&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Notice the new class called __LocalsDisplayClass$0&amp;#8230;1
that has been created. This is interesting culprit. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In essence how closures work in C# 2.0&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;is
that the compiler creates a new class that contains member variables correspond to
the local variables of CreateClosure() that are being used in the closure/anonymous
method that it defines. Thus you can see the local variable &amp;#8216;c&amp;#8217; of method
CreateClosure() can be seen in class __LocalsDisplayClass$0&amp;#8230;1. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So calling the CreateClosure method creates an instance
of the __Locals&amp;#8230; class. It then creates an old (classical) delegate to the __AnonymousMethod$0&amp;#8230;
method of the class. So the actual support for delegates in the CLR hasn&amp;#8217;t changed
at all. The delegate that is returned from the CreateClosure() method is a normal
(old C# 1.x type) delegate.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;All access to variables that are shared between the
CreateClosure() method and the anaymous method are accesses to members of the __Locals&amp;#8230;
class. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is IL code of CreateClosure()&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;.method private
hidebysig static class CMain/Closure 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;CreateClosure()
cil managed&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;//
Code size&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;30
(0x1e)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;.maxstack&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;3&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;.locals
init (class CMain/__LocalsDisplayClass$00000001 V_0,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;class
CMain/Closure V_1)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0000:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;newobj&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;instance
void CMain/__LocalsDisplayClass$00000001::.ctor()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;IL_0005:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;stloc.0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0006:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldloc.0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0007:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldc.i4.0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;IL_0008:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;stfld&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int32
CMain/__LocalsDisplayClass$00000001::c&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_000d:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldloc.0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_000e:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldftn&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;instance
void CMain/__LocalsDisplayClass$00000001::__AnonymousMethod$00000000(int32)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0014:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;newobj&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;instance
void CMain/Closure::.ctor(object,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;native
int)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0019:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;stloc.1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_001a:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;br.s&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;IL_001c&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_001c:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldloc.1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_001d:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ret&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;} // end of
method CMain::CreateClosure&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Notice some things in the above code &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;- An object of __LocalsDisplayClass$00000001 is created. 
&lt;br&gt;
- Access to the variable is actually access to the member &amp;#8216;c&amp;#8217; of this
class. 
&lt;br&gt;
- The delegate is created to the instance of the __LocalsDisplayClass$00000001 class
that was created and its __AnonymousMethod$00000000 method.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is the code of the anonymous method, which has
now become CMain/__LocalsDisplayClass$00000001::__AnonymousMethod$00000000(int32)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;.method public
hidebysig instance void&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;__AnonymousMethod$00000000(int32
n) cil managed&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;//
Code size&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;39
(0x27)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;.maxstack&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;5&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;.locals
init (int32 V_0)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0000:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldstr&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;"Closure:
n = {0}, c = {1}"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;IL_0005:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldarg.1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0006:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;box&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[mscorlib]System.Int32&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_000b:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldarg.0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_000c:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;dup&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;IL_000d:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldfld&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int32
CMain/__LocalsDisplayClass$00000001::c&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;IL_0012:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;dup&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0013:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;stloc.0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0014:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldc.i4.1&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span lang=IT style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-ansi-language: IT"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;IL_0015:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;add&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0016:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;stfld&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int32
CMain/__LocalsDisplayClass$00000001::c&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_001b:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ldloc.0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_001c:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;box&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[mscorlib]System.Int32&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0021:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;call&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void
[mscorlib]System.Console::WriteLine(string,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;object,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;object)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;IL_0026:&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;ret&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;} // end of
method __LocalsDisplayClass$00000001::__AnonymousMethod$00000000&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is quite exactly the code that we had written
into the CreateClosure() function. Except that the local variable &amp;#8216;c&amp;#8217;
is not a local variable any more. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What do you think will happen when there is a function
that defines two anonymous methods within it? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial color=#000000&gt;Code Showing Multiple Anonymous Methods / Closures
that share variables with its scope&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;//closure2.cs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;//Compile:
csc closure2.cs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;using System;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;class CMain&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;delegate
void Closure(int n);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
Closure t1,t2;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
void CreateClosure()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
c1 = 0;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
c2 = 0;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
c3 = 0;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
c4 = 0;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine("c4
= {0}",c4);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;t1
=&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;delegate(int n) {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine("Closure:
n={0}, c1={1}, c2={2}",&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;n,c1++,c2++);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;};&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;t2
= delegate(int n) {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine("Closure:
n={0}, c1={1}, c3={2}",&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;n,c1++,c3++);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;};&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
void &lt;/span&gt;
&lt;st1:place&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;Main&lt;/span&gt;
&lt;/st1:place&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;CreateClosure();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is what happens:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;img height=294 src="content/binary/cs_closure_2.gif" width=357 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Notice:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;- There is still only one class that maintains state.&lt;br&gt;
- The class has two methods (one for each of the anonymous methods) 
&lt;br&gt;
- The variables that are being used by either of methods are part of the class (c1,c2,
c3). 
&lt;br&gt;
- Variables that are not being used from either closure are not part of the class
(c4 is omitted).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One final look, what if the closure does not use any
variables of its enclosing scope, how would this work? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Code Showing an Anonymous Method / Closure
that is stateless&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;//closure3.cs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;//Compile:
csc closure3.cs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;using System;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;class CMain&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;delegate
void Closure(int n);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
Closure CreateClosure()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
c = 0;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
delegate(int n) {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine("Closure:
n = {0}",n);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;};&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
void &lt;/span&gt;
&lt;st1:place&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;Main&lt;/span&gt;
&lt;/st1:place&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Closure
c1 = CreateClosure();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Closure
c2 = CreateClosure();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c1(1);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c2(2);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The code generated looks like this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;img height=147 src="content/binary/cs_closure_3.gif" width=296 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;As expected there is NO hidden class generated in this
case. Why? Because these is no need for the anonymous method to save state. The anonymous
method itself is added to the class that contains the CreateClosure().&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One more case to look at: what happens when the closure
accesses both a local variable of the enclosing method as well as a member variable
of the class that the enclosing method is a part of? Because state is persisted in
a new class instance, how will the member variables of the original class be accessed?&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is C# code that shows this situation:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Code where closure accesses locals and class
members&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;//closure4.cs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;//Compile:
csc closure4.cs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;using System;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;class CMain&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;delegate
void Closure(int n);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
a = 10;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Closure
CreateClosure()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
c = 0;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
delegate(int n) {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine("Closure:
n = {0}, a = {1}, c = {0}",n,a++,c++);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;};&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
void &lt;/span&gt;
&lt;st1:place&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;Main&lt;/span&gt;
&lt;/st1:place&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;CMain
main = new CMain();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Closure
c1 = main.CreateClosure();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Closure
c2 = main.CreateClosure();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c1(1);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c2(2);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-SIZE: 9pt; COLOR: green; FONT-FAMILY: 'Courier New'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is what the generated code looks like:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;img height=238 src="content/binary/cs_closure_4.gif" width=346 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Notice that there is a member in the _Locals&amp;#8230;
class that is called &amp;lt; this &amp;gt;. The this pointer/reference refers back to the
original enclosing class where the anonymous method belonged. Thus it can access member
variables. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Notes&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I think C# closures were created as a by product of
trying to implement iterators into the language. The implementation of iterators involved
this sort of temporary class creation that preserved state of functions. (A little
like &lt;/font&gt;&lt;a href="http://www.research.att.com/~bs/bs_faq2.html#function-object"&gt;&lt;font face=Arial&gt;Bjarne
Stroutrup&amp;#8217;s Function Objects&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I don&amp;#8217;t know if there are reasons why this implementation
of anonymous methods cannot be called as proper closures. Anonymous methods cannot
use any ref or out type parameters of its enclosing function &amp;#8211; this is a limitation.
Does this limitation imply that they cannot be called closures? I don&amp;#8217;t know.
But other than that, it seems to serve the purpose of closures pretty well. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The fact that closures have been implemented as a compiler
level hack means that there is no overhead at all for code that does not take advantage
of these sort of feature. So there is no performance penalty on the CLR itself. Maybe
in time, when these features gain adequate popularity there will also exist efficient
means of integrating these features into the CLR in a way that does not affect functioning
of traditional code. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Once we have closures, we can implement a large variety
of constructs in the language (iterators being one of them). However since the syntax
is a little clunky and the actual implementation a little slow (because there is a
hidden managed class involved) this may never happen. All the same this is one amazing
feature to have in a mainstream language like C#. Maybe even a little too advanced
for some folk, so don&amp;#8217;t be surprised is the coding guidelines of your company
say NO to anonymous methods, the way they said to C++ macros once upon a time. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=9fe42970-09e3-44e2-a4d0-32d63139351a" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,9fe42970-09e3-44e2-a4d0-32d63139351a.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=33a6b160-1f9c-4abb-8627-58165753dcb5</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,33a6b160-1f9c-4abb-8627-58165753dcb5.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,33a6b160-1f9c-4abb-8627-58165753dcb5.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=33a6b160-1f9c-4abb-8627-58165753dcb5</wfw:commentRss>
      <title>C# Closures and Function Objects</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,33a6b160-1f9c-4abb-8627-58165753dcb5.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/05/21/CClosuresAndFunctionObjects.aspx</link>
      <pubDate>Fri, 21 May 2004 09:55:20 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Today I had a rather shocking realization. &lt;b&gt;I realized
that C# 2.0 supports closures&lt;/b&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It was rather shocking, because here I was running
up and down obscure languages looking for features like this and bang C# has it. I
was pointed to this blog entry by a good friend of mine at Microsoft: &lt;/font&gt;&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/DispForm.aspx?ID=8&amp;amp;Source=http://rotor.di.unipi.it/cisterni/Lists/My%2520Blog/AllItems.aspx"&gt;&lt;font face=Arial&gt;Antonio
Cisternino's Blog: Closures in CLR 2.0&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A lot of the content on Mr Cisternino&amp;#8217;s blog
is rather interesting and I would recommend a visit to &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/AllItems.aspx"&gt;&lt;font face=Arial&gt;http://rotor.di.unipi.it/cisterni/Lists/My%20Blog/AllItems.aspx&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The entry on closures is an interesting read. A quick
search on google, showed me that the rest of the world seemed to have realized that
C# has closures, a long time before I did. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Looking at closures brought back something from hazy
old memory from a time when I was more ignorant:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;Function Objects in C++ 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;What is a function
object?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;An object that
in some way behaves like a function, of course. Typically, that would mean an object
of a class that defines the application operator - operator(). 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;A function object
is a more general concept than a function because a function object can have state
that persist across several calls (like a static local variable) and can be initialized
and examined from outside the object (unlike a static local variable). For example: 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;class
Sum {&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
val;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Sum(int
i) :val(i) { }&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;operator
int() const { return val; }&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//
extract value&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
operator()(int i) { return val+=i; }&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//
application&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;};&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void
f(vector&amp;lt;int&amp;gt; v)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Sum
s = 0;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//
initial value 0&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;s
= for_each(v.begin(), v.end(), s);&lt;span style="mso-tab-count: 1"&gt; &lt;/span&gt;// gather
the sum of all elements&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout
&amp;lt;&amp;lt; "the sum is " &amp;lt;&amp;lt; s &amp;lt;&amp;lt; "\n";&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//
or even:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;cout
&amp;lt;&amp;lt; "the sum is " &amp;lt;&amp;lt; for_each(v.begin(), v.end(), Sum(0)) &amp;lt;&amp;lt; "\n";&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;Note that a function
object with an inline application operator inlines beautifully because there are no
pointers involved that might confuse optimizers. To contrast: current optimizers are
rarely (never?) able to inline a call through a pointer to function. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;Function objects
are extensively used to provide flexibility in the standard library. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is written by none other than Bjarne Stroustrup
and you can see the full FAQ here:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.research.att.com/~bs/bs_faq2.html"&gt;&lt;font face=Arial&gt;http://www.research.att.com/~bs/bs_faq2.html&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You might relate this to the brief discussion on method
instances in the previous entry &amp;#8216;&lt;/font&gt;&lt;a href="/CommentView,guid,d355277d-a942-4a50-aa03-d68413fd459c.aspx"&gt;&lt;font face=Arial&gt;The
Big Deal about Iterators&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;&amp;#8217;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Hopefully I will have a better understanding of how
C# does closures, soon enough. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=33a6b160-1f9c-4abb-8627-58165753dcb5" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,33a6b160-1f9c-4abb-8627-58165753dcb5.aspx</comments>
      <category>Languages</category>
      <category>Mish Mash</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=d355277d-a942-4a50-aa03-d68413fd459c</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,d355277d-a942-4a50-aa03-d68413fd459c.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,d355277d-a942-4a50-aa03-d68413fd459c.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=d355277d-a942-4a50-aa03-d68413fd459c</wfw:commentRss>
      <title>The ‘Big Deal’ about Iterators (Part 3)</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,d355277d-a942-4a50-aa03-d68413fd459c.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/05/19/TheBigDealAboutIteratorsPart3.aspx</link>
      <pubDate>Wed, 19 May 2004 14:09:21 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is an entry I have kept pending for a long time.
I should have had this out much earlier. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here I am going to talk about why iterators are a hard
feature to implement in a conventional stack based language. This will probably help
you understand some of the design decisions with respect to implementing iterators
in a language and, on the whole, make you a better programmer with respect to this
programming construct. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am assuming that you have read Parts 1 and 2&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="/CommentView,guid,dd0e61ef-6fb1-4156-9d16-81c20a6aa871.aspx"&gt;&lt;font face=Arial&gt;Iterators
in Ruby (Part - 1)&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="/CommentView,guid,02da61dd-1e35-4a36-b46b-aa3a605b2ad6.aspx"&gt;&lt;font face=Arial&gt;Warming
up to using Iterators (Part 2)&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;After you have read this entry you should be in better
light to grasp Parts 4 and 5.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="/CommentView,guid,e5126078-543f-49bf-a83a-325c11ec7682.aspx"&gt;&lt;font face=Arial&gt;SICP,
Fiber api and ITERATORS ! (Part 4)&lt;/font&gt;&lt;/a&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="/CommentView,guid,fd10bfa8-1aeb-4353-84c8-cd80e418424f.aspx"&gt;&lt;font face=Arial&gt;Implementation
of Iterators in C# 2.0 (Part 5)&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;Method Calls and the Stack Frame 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Since you have seen some samples of iterator based
code in Part 2 lets take a look at how an iterator works. Before we delve into the
related issues, first let us take a look at how method calls work on the C stack.
(We could have taken an stack based language here, for example .Net IL, but I figured
it is easier to stick to C). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Consider the following functions&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;void caller()&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
a;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
b;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
sum = callee(a, b);&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;int callee(int a, int b)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
temp = a + b;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
temp;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;That is amazingly simple. However what happens here?
When I say what happens here, I mean to ask what happens here at the system stack
level.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;To do that lets take a look at
the dissembly of these functions. If you were to compile this code with the vc++ compiler,
you could use the following switch to generate assembly code.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;gt;cl /Facode.cpp.asm code.cpp&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;?callee@@YAHHH@Z PROC NEAR&lt;span style="mso-tab-count: 4"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;;
callee&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;; File d:\roshanj\work\cpp\iter\func.cpp&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;; Line 2&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;push&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp; &lt;/span&gt;ebp&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;mov&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ebp,
esp&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;push&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp; &lt;/span&gt;ecx&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;; Line 3&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;mov&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;eax,
DWORD PTR _a$[ebp]&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;add&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;eax,
DWORD PTR _b$[ebp]&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;mov&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;DWORD
PTR _temp$[ebp], eax&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;; Line 4&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;mov&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;eax,
DWORD PTR _temp$[ebp]&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;; Line 5&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;mov&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;esp,
ebp&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;pop&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ebp&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ret&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;?callee@@YAHHH@Z ENDP&lt;span style="mso-tab-count: 5"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;;
callee&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;?caller@@YAXXZ PROC NEAR&lt;span style="mso-tab-count: 4"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;;
caller&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;; Line 8&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;push&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp; &lt;/span&gt;ebp&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;mov&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ebp,
esp&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sub&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;esp,
12&lt;span style="mso-tab-count: 5"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;;
0000000cH&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;; Line 11&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;mov&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;eax,
DWORD PTR _b$[ebp]&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;push&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp; &lt;/span&gt;eax&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;mov&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ecx,
DWORD PTR _a$[ebp]&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;push&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp; &lt;/span&gt;ecx&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;call&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp; &lt;/span&gt;?callee@@YAHHH@Z&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;;
callee&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;add&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;esp,
8&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;mov&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;DWORD
PTR _sum$[ebp], eax&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;; Line 12&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;mov&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;esp,
ebp&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;pop&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ebp&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ret&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;0&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;?caller@@YAXXZ ENDP&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The stack frame of the caller function looks like this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;
&lt;v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"&gt;
&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;
&lt;v:formulas&gt;
&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;
&lt;/v:formulas&gt;
&lt;v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"&gt;&lt;/v:path&gt;
&lt;o:lock aspectratio="t" v:ext="edit"&gt;
&lt;img height=123 src="content/binary/Iterators_general_stackframe1.gif" width=243 border=0&gt;
&lt;/o:lock&gt;
&lt;/v:shapetype&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;And the when the caller() is calling the callee() then
both the methods have their stack-frames mounted. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;img height=246 src="content/binary/Iterators_general_stackframe2.gif" width=243 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;In Intel based systems the C stack grows downward
in memory, which means that each item that is added to the stack causes the top of
the stack (SP) to have a lesser address value. So the right way to draw these diagram
would have been to draw them upside down. But that detail is not relevant here and
so I have depicted them as a conventional stack that grows upwards. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When the callee() returns, the stack looks like the
initial stack diagram and the variable &amp;#8216;sum&amp;#8217; contains its required value. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;img height=123 src="content/binary/Iterators_general_stackframe1.gif" width=243 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;To reiterate, what happens is that a method that is
currently running uses the stack for storing its local variables &amp;#8211; or more generally
the state of the running method is preserved on the stack. When a method is called,
it builds its own stack frame on top of whatever was already on the stack. The called
method uses the stack frame to save its state, irrespective of what other methods
are already on the stack. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You might have heard of this concept called a stack-overflow.
That happens when methods calls happen to such an extent that there is not more free
space left on the stack for the stack frame of a new method to be created. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Whenever a method returns, the part of the stack that
is used for its variables is freed up &amp;#8211; or so to speak, the methods stack frame
is torn down. So when a method returns, its state information, that was on the stack
is completely lost. This is necessary, because the parent function or method, might
go on to call other methods that go on to use same stack space subsequently. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So let us say there is a calling pattern like this &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;function a()&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;function b()&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;call
a()&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;function caller()&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;call
a()&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;call
b()&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The stack usage will look like this &amp;#8211; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;img height=115 src="content/binary/Iterators_general_stackframe3.gif" width=529 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now that we have a reasonable idea of how the stack
is used across method calls (though in reality there are so many many approaches),
lets move on to iterators.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;Iterators&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial&gt;&lt;font color=#000000&gt;Look at the following ruby snippet that shows
an iterator. &lt;i&gt;If you have an interest in C/Cpp/C# and couldn&amp;#8217;t care less about
Ruby, don&amp;#8217;t throw your hands up in the air &amp;#8211; the language is used here
as an example of a language that implements iterators (and rather well at that), which
I am using to communicate the idea. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/i&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def callee()&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;for
i in 1..10&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
i&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;end&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def process(v)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
(v * 10)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def caller()&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;callee()
{|value|&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;value
= process(value)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
value&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you recall the behavior of the iterator from Part
1 and 2, you will remember that when caller() calls callee() and the callee() invokes
the yield statement, the control is back at the caller(). In this case, the value
of &amp;#8216;i&amp;#8217; is yielded from callee() which is received in caller() as value. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In C code, when the control returns to the calling
function the assumption is that the called function is dead on the stack and that
the stack frame is free for subsequent method calls, as shown in the stack diagram
above. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If we have a similar diagram for the this ruby code,
how would we draw it? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;img height=115 src="content/binary/Iterators_general_stackframe4.gif" width=457 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is where we hit our first wall. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Assume that the caller() calls callee() and the callee()
has yielded value 1. Now the stack frame of callee() is torn down in the old C way
and the process() method is called which goes on to use the same area of the stack
that was one used by callee(). After that caller() has done whatever it needs to do
with the value it received from callee() it tries to invoke callee() again so that
it can get the next value. This is where we hit the wall. The callee() cannot return
the next value simply because the previous value it has for &amp;#8216;i&amp;#8217; is lost
when its stack frame got torn down. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In other words, on a conventional C stack, the callee()
state is lost and therefore cannot resume execution from the point of a yield. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What work arounds do we have to this issue? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Let us assume that what Ruby does is simply a compiler
hack &amp;#8211; let us assume that it never really tears down the stack frame of the
callee() at all, but instead it ensures that function returns back to the caller()
but with the callee() stack frame still in place. That would look like this &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;img height=97 src="content/binary/Iterators_general_stackframe5.gif" width=360 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;While this is a nice diagram to look at, what does
this mean? Where will the stack frame of the subsequent call to process() go? It cannot
over-write the callee() stack frame &amp;#8211; so it has to go above it. Like this?&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;img height=97 src="content/binary/Iterators_general_stackframe6.gif" width=312 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Woo, now wait a minute, how does the caller() function
know how much of the stack the callee() function is using to be able to do this? This
is a difficult question to answer. Remember that the callee() is a proper function
that can be using a variable amount of the stack at any point of time. So the caller()
cannot predict the stack usage of the callee() but lets assume that the callee() passes
back the information of its stack usage back along with the value that it is yielding. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Ok, so that would solve the problem of how the process()
function uses the stack. But there is one more issue. What is the code block inside
the caller() (the one that receives the yielded value) needs to push a value onto
the stack? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If the code block inside the caller, needs to push
a value onto the stack, then the pushed value will go on to overwrite the stack-frame
of the callee above it. The obvious way to fix the problem is to shift the entire
stack pointer to the top of the stack, above the callee() also. You can visualize
it like this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;img height=97 src="content/binary/Iterators_general_stackframe7.gif" width=392 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;While this could work, there is one more issue &amp;#8211;
the local member variables of a function are accessed via EBP offsets. Now this is
fine when local variables occur at known distances from the base of the stack frame
for the function. To see this happen, you might want to refer back to the assembly
code I posted towards the beginning of this article. You notice that most of the member
variables are being accessed as _a$[ebp] or _b$[ebp], or similar syntax. The _a$ here
does nothing but add a fixed positive offset to the EBP pointer. For the access of
local variables when code is in the yield&amp;#8217;s parameter block region of the caller()
these rules would have to change, as there is an issue of adding an additional offset.
The additional offset is introduced because now there is the stack frame of the callee()
sitting squarely in the middle of what should have been the stack frame of the caller(). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;These issues crop up when using single iterators. If
using multiple iterators or nested iterators and when used in conjunction with stack
intensive operations like recursion, the picture because very complicated. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Alternative approaches of State maintenance
and the concept of Method instances&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;While it should be clear that, to implement iterators
in a language the must support the idea of functions maintaining their state even
after they surrender control to their calling methods &amp;#8211; it is not very clear
as to how this can be implemented on a conventional C stack. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One approach is to go for a &amp;#8216;stackless&amp;#8217;
implementation. What that means is that function activations or stack frames are treated
as allocated memory blocks on the heap and each function instance (when you call a
function it needs to create a stack frame and that can be considered a function or
method instance) lives on the heap like any other dynamically allocated object. These
mini stacks as specific to function instances and so have no real concept of colliding
with each other due to sharing a larger OS/platform maintained stack. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I believe languages like lisp/scheme behave in this
manner with respect to the language stack. (I have been told this and I hope this
is correct).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Another alternative is to approach the problem like
this. Assume that the callee used only static variables. Immediately, the issue of
maintaining state of variable of the callee on the stack is eliminated. The only issue
then, is to resume execution of the function from the correct place (immediately past
the yield) when the function is called again. This can be easily achieved by saving
the resume position into an additional variable and implementing a switch case goto
construct at the beginning of the function. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now since it is persisting state in static variables
we cannot use this recursively or in any other fashion. But we could fix this if we
created a structure/class that contains member variables corresponding to the local
variables of the function and use an instance of this structure in the function instead
of using proper static variables. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Languages such as C# and Python use a similar approach
to maintaining state of iterators between calls. You can read more about this in the &lt;/font&gt;&lt;a href="/CommentView,guid,fd10bfa8-1aeb-4353-84c8-cd80e418424f.aspx"&gt;&lt;font face=Arial&gt;Part
5&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; of this series. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;For constructs like iterators to be supported in .Net
and similar runtimes, in a native way, will require substantial changes in the way
the runtime manages stack-frames and similar entities. Basically languages and runtimes
need to be retro-fitted with a concept of function and code block instances the same
way object oriented programming is fitted with concepts of class instances called
objects.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Languages like Sun Microsystems&amp;#8217; Self build on
similar concepts for methods/function instantiation. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you give some of the ideas here a little thought,
you should be well on your way to dreaming about new languages and fancy programming
constructs.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=d355277d-a942-4a50-aa03-d68413fd459c" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,d355277d-a942-4a50-aa03-d68413fd459c.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=fc269607-7c39-4f96-b7c6-edd2247413a4</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,fc269607-7c39-4f96-b7c6-edd2247413a4.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,fc269607-7c39-4f96-b7c6-edd2247413a4.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=fc269607-7c39-4f96-b7c6-edd2247413a4</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>XAML and the markups: Introducing WFML - WinForms Markup Language</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,fc269607-7c39-4f96-b7c6-edd2247413a4.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/04/29/XAMLAndTheMarkupsIntroducingWFMLWinFormsMarkupLanguage.aspx</link>
      <pubDate>Thu, 29 Apr 2004 10:49:08 GMT</pubDate>
      <description>&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Tahoma; mso-bidi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.0pt"&gt; 
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;I
thought of putting together some of my old mails and user group posting as blog entries,
with some patches so that they are&amp;#8217; blogopatible&amp;#8217;. They would have ended
up on my blog, if I had a blog when I made these posts. I feel some of these are of
lasting importance, at least with respect to the impressions they had on me. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;All of these are personal opinions,
probably more relevant in the context that they were originally written. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 12pt"&gt;
&lt;/span&gt;&lt;/font&gt;&amp;nbsp;&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 12pt"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Tahoma; mso-bidi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.0pt"&gt;-----Original
Message-----&lt;br&gt;
&lt;b&gt;From:&lt;/b&gt; James, Roshan&lt;br&gt;
&lt;b&gt;Sent:&lt;/b&gt; &lt;/span&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;
&lt;st1:date Month="12" Day="9" Year="2003"&gt;
&lt;span style="FONT-FAMILY: Tahoma; mso-bidi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.0pt"&gt;Tuesday,
December 09, 2003&lt;/span&gt;
&lt;/st1:date&gt;
&lt;/font&gt;&lt;span style="FONT-FAMILY: Tahoma; mso-bidi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.0pt"&gt;&lt;font color=#000000&gt; 11:57
PM&lt;br&gt;
&lt;b&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;Subject:&lt;/b&gt; XAML and markups: Introducing
WFML - WinForms Markup Language&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Hi Folk, &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face=Arial color=#000000&gt;Ever since Linux Bangalore I have been thinking about
something that Miguel de Icaza had demoed on stage. He was showing Mono&amp;#8217;s UI,
Glade, and showed how Glade generates UI from XML markup. They (Miguel and Nat) were
also joking as to how XAML is an idea that they had thought of 6 years back &amp;#8211;
the idea of using XML markup for representing UI and separating 'business logic' from
UI.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face=Arial color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;He
also went on to show how Glade is used to generate GTK# UI in linux. A '.glade' file
is simply an xml file that contains tags that correspond to the properties of the
controls (or widgets as they call them). &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;(I pulled glade file
off the net to give you an idea of what it looks like&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;GLADE-INTERFACE&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&amp;lt; widget class="GtkWindow"
id="window2"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="visible"&amp;gt;True&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="title" translatable="yes"&amp;gt;window2&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="type"&amp;gt;GTK_WINDOW_TOPLEVEL&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="window_position"&amp;gt;GTK_WIN_POS_NONE&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="modal"&amp;gt;False&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="resizable"&amp;gt;True&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="destroy_with_parent"&amp;gt;False&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;
child&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
widget class="GtkButton" id="button1"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="border_width"&amp;gt;10&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="visible"&amp;gt;True&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="can_focus"&amp;gt;True&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="label" translatable="yes"&amp;gt;button1&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="use_underline"&amp;gt;True&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
property name="relief"&amp;gt;GTK_RELIEF_NORMAL&amp;lt; /property&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
/widget&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&amp;lt;
/child&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&amp;lt; /widget&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&gt;
)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face=Arial color=#000000&gt;The strange thing was how they used glade files - in
XAML you compile the xml file to generate a class (or what MS calls a partial class,
one that can be extended elsewhere). In glade they did no such thing, they simple
wrote a cs file and called one Glade API function passing it the name of '.glade'
file. That returned some kind of object and presto they had their UI. Now the claim
was that this really separates the UI from the code and as a matter of fact the XML
can be chnaged after the exe file has been compiled. Changes to the XML will reflect
in the UI without recompilation of anything. They also mentioned that Microsoft hasn&amp;#8217;t
figured out how to do this yet. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;(Here is fragment of
c# code that uses the .glade&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;using
Gtk;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;using
Gnome;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;using
Glade;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;using
GtkSharp;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
class GladeTest&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;/*
If you want to access the glade objects you have to "import" them.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;*
This is not required, but else you can only work with the&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;*
pre-defined signal handlers */&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[Glade.Widget]&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Button
button1;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
GladeTest (string[] args) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Application.Init();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;/*
This loads the glade file glade.glade, 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;*
selects window2 and connects it to the current object,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;*
which is the class GladeTest here. */&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Glade.XML
gxml = new Glade.XML ("file.glade", "window2", null);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;gxml.Autoconnect
(this);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;button1.BorderWidth=10;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Application.Run();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Times New Roman'"&gt;)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Now
this got me thinking about how they implemented this dynamic behavior - as result
of which WFML was born. It was rather surprising how easy this was to do. I am sure
Miggy's code will be better and more optimized, but I think my general direction is
correct. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face=Arial color=#000000&gt;WFML, in short provides (or at least hopes to provide)
a markup language for UI that simply does not have to compiled (in the conventional
sense). WFML UI is actually WinForms based UI, WFML by itself cannot add any features
that are not present in WinForms. What it does is that it lets you write very clean
looking code that does not have a clutter for UI itself. The entire UI of the program
is expressed in an external XML file, called a .wfml file. Now if you have ever tried
writing a Win forms application by hand without studio, you will remember how hard
it is to remember so many of the house-keeping things required - take a look at some
WFML based code:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;//win.cs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;using System;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;using System.Windows.Forms;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;using System.Windows.Forms.Markup;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;class CMain&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;span style="COLOR: navy"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
void &lt;/span&gt;
&lt;st1:place&gt;
&lt;span style="COLOR: navy"&gt;Main&lt;/span&gt;
&lt;/st1:place&gt;
&lt;span style="COLOR: navy"&gt;()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;IAttachable
win = new Wfml().CreateUserInterface("win.wfml","MainWindow");&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Application.Run((Form)win);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Courier New"&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Simple ? This is a C# file that uses the WFML library.
The markup lib being a pure .Net assembly can be used by any .Net language, - C#,
VB, C++, Jscript, VJ# etc. Now what you need is a WFML file that specifies the UI.
And you simply write the .wfml file like this (win.wfml):&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
Window 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Name="MainWindow"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Height="200"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Width="400" 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;/&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face=Arial&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;As you can see, the WFML is simply an XML file with
certain tags that the WFML library understands. The advantage of using something like
WFML is that you can completely change this XML at will and the UI of your program
can be completely changed. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now compile the cs:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face=Arial color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;csc /t:winexe /r:System.Windows.Forms.Markup.dll
win.cs&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face="Courier New" color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Run win.exe and you will see an empty window&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face=Arial color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The following .wfml code displays a button and a text
box for the same win.exe program. The program need not be edited or recompiled, only
the .wfml file needs to be changed. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&amp;lt; Window&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Name="MainWindow"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Height="200"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Width="400" 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Text="Main
Window"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
Button Name="mybutton" 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Top="10"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;Text="Click
Me"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;/&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&amp;lt;
TextBox 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Name="tbox"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Top="40"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Left="5"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Width="200"&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;/&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: #993300"&gt;&lt;font face=Arial&gt; Window&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face=Arial&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;font color=#000000&gt;(What tags and
attributes are allowed within a WFML? Every attribute that you set in a tag has to
be a property of the corresponding WinForms type. That is to say that if you want
to put a attribute called &amp;#8216;Text&amp;#8217; in the &amp;#8216;Window&amp;#8217; tag, then
the class System.Windows.Form.Window should support a property called Text. WFML being
a very simple system is case sensitive and provides no error feedback if something
is wrong.)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;And you can even attach event handlers and write back
to the UI: &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;using System.Windows.Forms;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;using System.Windows.Forms.Markup;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;using System;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;class CMain&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;public
TextBox tbox;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
void clicked(object sender, EventArgs e)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;tbox.Text+="+
";&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
void &lt;/span&gt;
&lt;st1:place&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;Main&lt;/span&gt;
&lt;/st1:place&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;IAttachable
win = new Wfml().CreateUserInterface("win.wfml","MainWindow");&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;CMain
cm = new CMain();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;win.AttachConsumer(cm);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Application.Run((Form)win);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy; FONT-FAMILY: 'Courier New'"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Do try some WFML, the supported types are Button, TextBox
and Label - but I guess the rest can be added easily.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Now
I don't think this was anywhere as hard as they were making it out to be on stage.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face=Arial color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Roshan James&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;------------------------------&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="mso-spacerun: yes"&gt;&lt;font face=Arial color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You can &lt;a href="content/binary/wfml.zip"&gt;download
the WFML.zip file here&lt;/a&gt;. This also contains the demos that I had for this UG post.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;While
I never did continue on the WFML, folk did mail me back asking about the WFML assuming
it was part of a larger UI framework. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Of course, capital negatives of the approach are that
there is no IDE to ease development of WFML and such, but the idea itself is rather
interesting. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;How WFML actually works, as you might have guess is
that it uses reflection API to dynamically generate a System.Windows.Form type that
is customized according to the WFML file. This runtime generated type also runs reflection
based code on its caller and appropriately latches up event handlers dynamically.
Also it uses reflection to assign references of the caller to classes to the actual
objects created in the generated Form class. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You however need not compare XAML to WFML or like approaches
because XAML is a whole different beast. Differences start with be67ing vectored based
don&amp;#8217;t stop any time soon. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=fc269607-7c39-4f96-b7c6-edd2247413a4" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,fc269607-7c39-4f96-b7c6-edd2247413a4.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
      <category>Zeitgeist</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=fd10bfa8-1aeb-4353-84c8-cd80e418424f</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,fd10bfa8-1aeb-4353-84c8-cd80e418424f.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,fd10bfa8-1aeb-4353-84c8-cd80e418424f.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=fd10bfa8-1aeb-4353-84c8-cd80e418424f</wfw:commentRss>
      <slash:comments>9</slash:comments>
      <title>Implementation of Iterators in C# 2.0 (Part 5)</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,fd10bfa8-1aeb-4353-84c8-cd80e418424f.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/04/25/ImplementationOfIteratorsInC20Part5.aspx</link>
      <pubDate>Sun, 25 Apr 2004 11:16:33 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="/CommentView,guid,dd0e61ef-6fb1-4156-9d16-81c20a6aa871.aspx"&gt;&lt;font face=Arial&gt;Iterators
in Ruby (Part - 1)&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="/CommentView,guid,02da61dd-1e35-4a36-b46b-aa3a605b2ad6.aspx"&gt;&lt;font face=Arial&gt;Warming
up to using Iterators (Part 2)&lt;/font&gt;&lt;/a&gt;
&lt;br&gt;
&lt;font face=Arial color=#000000&gt;&amp;lt; I am yet to write a part 3 &amp;gt;&lt;br&gt;
&lt;/font&gt;&lt;a href="/CommentView,guid,e5126078-543f-49bf-a83a-325c11ec7682.aspx"&gt;&lt;font face=Arial&gt;SICP,
Fiber api and ITERATORS ! (Part 4)&lt;/font&gt;&lt;/a&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I had a look at the implementation of iterators in
C#. What follows is based on code generator I have seen on the C# Whidbey post PDC
release. Things might have changed by now as things are moving to technology preview
phase.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is example code that is present in MSDN:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;// yield-example.cs&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;using System;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;using System.Collections;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;public class List&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
static IEnumerable Power(int number, int exponent)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
counter =0;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
result = 1;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;while(counter++
&amp;lt; exponent)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;result
= result * number;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
result;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;
&lt;o:p&gt;
&lt;font face="Courier New"&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;span style="COLOR: navy"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
void &lt;/span&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;
&lt;st1:place&gt;
&lt;span style="COLOR: navy"&gt;Main&lt;/span&gt;
&lt;/st1:place&gt;
&lt;span style="COLOR: navy"&gt;()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//
Display powers of 2 up to the exponent 8:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;foreach(int
i in Power(2, 8))&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.Write("{0}
", i);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Notice the introduction of a nice little &amp;#8216;yield&amp;#8217;
keyword? The behavior of C# iterators in this context is a lot like ruby iterators
that I have been talking about in previous articles. Knowing a little about the state
management requirements for iterators and the fact that the CLR is stack based, how
are iterators implemented in C#?&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The implementation of iterators in C# is not driven
by the CLR in any way, it is completely implemented in the language as a compiler
construct. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Let me explain what the compiler tries to do &amp;#8211;
the compiler examines the function that does the yield &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
static IEnumerable Power(int number, int exponent)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
counter =0;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
result = 1;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;while(counter++
&amp;lt; exponent)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;result
= result * number;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
result;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Lets just ignore the yield statement for now and look
at the method as thought it contained only a loop. It would basically look like this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt; 
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
static IEnumerable Power(int number, int exponent)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;
[&lt;/span&gt;initial code]&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;while([loop
condition])&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
[&lt;/span&gt;loop body]&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;
[&lt;/span&gt;post loop code]&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is then generated into a sequence of IL statement
blocks that have the following jumps between them:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;
&lt;v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"&gt;
&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;
&lt;v:formulas&gt;
&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;
&lt;/v:formulas&gt;
&lt;v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"&gt;&lt;/v:path&gt;
&lt;o:lock aspectratio="t" v:ext="edit"&gt;
&lt;img height=307 src="content/binary/Iterators_cs1.gif" width=175 border=0&gt;
&lt;/o:lock&gt;
&lt;/v:shapetype&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now, what yield would require is that the method exit
at each point a yield statement occurs. The next time the method is invoked, execution
continues immediately past the yield statement with all variables preserving their
values. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In the CLR, when a method returns its stack frame is
torn down. So there is no way that the local variables can actually preserve state.
The solution taken by the C# team is turn the method that implements the yield statement
into a class. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Such a class would &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l1 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Have
all local variables of the method as members of the class&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l1 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Have
a special variable that hold the value that is being yielded.&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l1 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Have
a special variable to indicate where the method should continue from, the next time
it is invoked. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When the caller of such a method runs and encounters
the foreach loop that invokes the iterator an object of this class gets created. This
object is maintained as long as the foreach lop is running. When the loop exits the
object is disposed.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;That&amp;#8217;s how iterators are implemented in C#. :)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Now here are some details:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;img height=101 src="content/binary/Iterator_cs_ildasm1.gif" width=265 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The method that implements the iterators generates
not one but two classes. Both the classes are generated as nested/inner classes to
the class that contains the method. The classes are named as 
&lt;br&gt;
(method name)$(number )_IEnumerableImpl&lt;br&gt;
(method name)$(number)_IEnumeratorImpl&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am not sure about the exact reasoning behind the
generation of two classes. The earlier standard for writing enumerators in C# probably
required, but from the standpoint of implementing iterators, I don&amp;#8217;t understand
the need. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The first of these, the IEnumerableImpl simply creates
an instance of the second class and returns it to the caller.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The second class IEnumeratorImpl is the interesting
one. This class has data members for all the local variables as well as our two special
data members. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;img height=328 src="content/binary/Iterators_cs_ildasm2.gif" width=525 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Compare the data members (the cyan colored diamond
shapes) to the original&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;local variables
of the method. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
static IEnumerable Power(int number, int exponent)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;int
counter =0;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;int
result = 1;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;while(counter++
&amp;lt; exponent)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;result
= result * number;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
result;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: navy"&gt;&lt;font face="Courier New"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The parameters number and exponent are there as such
and the local variables counter and result are there with some name mangling (I would
expect this is to avoid clashes with duplicate names in nested scopes, though that
is not allowed in C# (duh?)). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The two new members on the class are &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo2; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;$PC&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo2; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;$_current&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;$_current is the member that holds the yielded value.
In the case of the above method, $_current holds the value of &amp;#8216;result&amp;#8217;.
It is an &amp;#8216;object&amp;#8217; type for there will be a nice boxing and gc overhead
when moving around an int type &amp;#8211; I don&amp;#8217;t know why something was not done
for special casing value types. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;$PC is the interesting variable. Remember our little
diagram above that showed execution through IL. In the case of the iterators, the
method does not simply execute in a loop like shown there, but executes one iteration
of the loop on each call. The $PC is the variable that keeps track of where the code
should jump to, the next time the method is called. Understandably $PC is someone
idea of program counter ;) &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The code method called MoveNext() in the class actually
does the work that the method power() originally did. This is what is look like in
IL code. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;img height=685 src="content/binary/Iterators_cs2.gif" width=212 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Sorry I am not very good with diagrams, but if you
look at it you will see that the code is simply built for repeated invocation. Each
time according to $PC the code braches to a new location and executes. It then sets
the value of $PC to a new location of entry before the function exits. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In C# the yielded value is assigned to the $_current
member variable and the MoveNext() itself exits by returning a true or false. A true
indicates that the method returned through a yield and the false indicates that the
method has completed execution. Subsequent calls to the method, after it has returned
false will simply cause the method to return false and the $_current will not be updated. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So how does the caller of an iterative method behave?
In this case its the main. The &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;caller
simply does the following &amp;#8211; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: navy"&gt;&lt;font face=Arial&gt;Invoke Power$00000000__IEnumerableImpl.
GetEnumerator() to get an instance of Power$00000000__IEnumeratorImpl&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: navy"&gt;
&lt;o:p&gt;
&lt;font face=Arial&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: navy"&gt;&lt;font face=Arial&gt;Invoke Power$00000000__IEnumeratorImpl.MoveNext()&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: navy"&gt;
&lt;o:p&gt;
&lt;font face=Arial&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: navy"&gt;&lt;font face=Arial&gt;If result is true, use invoke Power$00000000__IEnumeratorImpl.get_Current()
which will return the $_current. The foreach loop will cause the MoveNext() to be
invoked again after the reurned value is consumed.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: navy"&gt;
&lt;o:p&gt;
&lt;font face=Arial&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;span style="COLOR: navy"&gt;&lt;font face=Arial&gt;If result is false, break out of foreach
loop. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;After the loop breaks out the instance of Power$00000000__IEnumeratorImpl
is dispose and is available for garbage collection.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am looking forward to the beta preview to see f things
have changed. There is a lot of rather redundant code generated by the compiler here
that I have not mentioned. When you are reading IL you might want to skip over those
parts. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Probably in the future the CLR will contain constructs
that enable true iterators and closures. Present day processors don&amp;#8217;t natively
support such constructs and so implementation will have to be hacks on the C stack
or using some kind of class-object mechanism like shown here.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;As a foot note I would like to mention that the Python
also implements iterators in a manner similar to C#. There the function that yields
is also converted into a class that maintains state. I believe the MoveNext() equivalent
in Python is simply next(). Python however raises an exception to signal end of iteration.
C# uses a Boolean return value to indicate this. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If this topic holds your interest then I recommend
reading:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html"&gt;&lt;font face=Arial&gt;Coroutines
in C&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; 
&lt;br&gt;
by Simon Tatham&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://msdn.microsoft.com/msdnmag/issues/04/05/C20/default.aspx"&gt;&lt;font face=Arial&gt;C#
2.0 Create Elegant Code with Anonymous Methods, Iterators, and Partial Classes 
&lt;br&gt;
&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;by Juval Lowy (MSDN Mag)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www-106.ibm.com/developerworks/library/l-pycon.html?n-l-9271"&gt;&lt;font face=Arial&gt;Charming
Python: Iterators and simple generators - New constructs in Python 2.2&lt;/font&gt;&lt;/a&gt;
&lt;br&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;by David Mertz (developerWorks)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=fd10bfa8-1aeb-4353-84c8-cd80e418424f" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,fd10bfa8-1aeb-4353-84c8-cd80e418424f.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=8db48b27-c3c9-4782-a595-7656e63305b1</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,8db48b27-c3c9-4782-a595-7656e63305b1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,8db48b27-c3c9-4782-a595-7656e63305b1.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=8db48b27-c3c9-4782-a595-7656e63305b1</wfw:commentRss>
      <title>My first look at Groovy… groovy!</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,8db48b27-c3c9-4782-a595-7656e63305b1.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/04/22/MyFirstLookAtGroovyGroovy.aspx</link>
      <pubDate>Thu, 22 Apr 2004 08:09:35 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I downloaded and tried the new programming language
Groovy today. In short groovy is like having Ruby on JVM. Maybe only better, because,
it now has the power of the whole JVM to leverage. This is the homepage:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://groovy.codehaus.org/"&gt;&lt;font face=Arial&gt;http://groovy.codehaus.org&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;&lt;?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /&gt;
&lt;v:shapetype id=_x0000_t75 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;
&lt;v:stroke joinstyle="miter"&gt;&lt;/v:stroke&gt;
&lt;v:formulas&gt;
&lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 1 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum 0 0 @1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @2 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @3 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @0 0 1"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @6 1 2"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelWidth"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @8 21600 0"&gt;&lt;/v:f&gt;
&lt;v:f eqn="prod @7 21600 pixelHeight"&gt;&lt;/v:f&gt;
&lt;v:f eqn="sum @10 21600 0"&gt;&lt;/v:f&gt;
&lt;/v:formulas&gt;
&lt;v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"&gt;&lt;/v:path&gt;
&lt;o:lock v:ext="edit" aspectratio="t"&gt;
&lt;img height=112 src="content/binary/groovy-logo.png" width=227 border=0&gt;
&lt;/o:lock&gt;
&lt;/v:shapetype&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;The language is a stunner. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;There is a lot of neat language design going on here.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://wiki.codehaus.org/groovy/BlocksAndClosures"&gt;&lt;font face=Arial&gt;http://wiki.codehaus.org/groovy/BlocksAndClosures&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Imagine something like Ruby actually being available
to code JSP, beans and what not in the Java world. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Being from the .Net background, I wish this was being
done for the CLR. Imagine the power to the multi language support of the CLR brought
into something like Ruby. For now I am content with gaping at features like this: &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000080&gt;def counter(a) &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000080&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000080&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c
= a; &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000080&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;x
= {c +=1; c}; &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000080&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;x&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000080&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000080&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000080&gt;a_counter = counter(0)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000080&gt;b_counter = counter(20)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000080&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000080&gt;println(a_counter())&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000080&gt;println(b_counter())&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000080&gt;println(a_counter())&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000080&gt;println(a_counter())&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000080&gt;println(b_counter())&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial&gt;&lt;font color=#000000&gt;This actually works. &lt;b&gt;Real closures! &lt;/b&gt;
&lt;br&gt;
&lt;i&gt;If you are a lost C or VB soul, what is happening is that the function/method called
counter() creates and returns a closure called x. A closure is a block of code that
maintains state and scope based access to its variables. So closure x has the maintains
state and has access to the variables of the method counter().&lt;o:p&gt;&lt;/o:p&gt;
&lt;/i&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;a_counter and b_counter are instance of the
closure in the counter() method, that live after the invocations to the counter()
method has exited. You can see that state is maintained between calls as the value
of &amp;#8216;c&amp;#8217; is incremented in each successive call. &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is way ahead of languages like C# which are just
grappling with their implementation of yield. This is of course not to blame the C#
team, because admittedly the concept of programming with closures is yet to hit &amp;#8216;the
masses&amp;#8217;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Groovy seems to do a whole pile of exciting things
that Ruby can do&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Closures&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Iterators
and Blocks&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Regular
expressions &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Flexible
collection types&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Dynamic
Method Invocations and types&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I haven&amp;#8217;t seen any mention of continuations,
extendible classes, mixins and the like yet. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Of course, being on the JVM is slow and implementing
a lot of features like the ones above, accounts for expensive constructs, which make
the language even slower. However for most scripting language speeds, it should be
acceptable. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What I think is more important is that languages of
Ruby stature are being implemented on popular OO virtual machines. This is a sign
for a possible trend in the future &amp;#8211; a good one. It will be interesting times
ahead when we have dynamic languages and functional languages move onto popular VMs. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I really like C and I think that &lt;i&gt;simplicity is a
feature (EricGu), &lt;/i&gt;however there is a real wealth of possibilities to be gleaned
if constructs that have long been available only to students and researchers actually
hit popular programming. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am excited about the possibilities of a Ruby like
implementation under .Net. Python is already getting there with Jim Hugunin and his
$g(IronPython).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here are the folk behind Groovy:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://groovy.codehaus.org/team-list.html"&gt;&lt;font face=Arial&gt;http://groovy.codehaus.org/team-list.html&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you enjoy programming in Ruby or in a language that
supports lists, iterators, closures etc, you might enjoy Groovy. It is still under
development, so there might be things that are missing. You will also have to get
the JVM.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=8db48b27-c3c9-4782-a595-7656e63305b1" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,8db48b27-c3c9-4782-a595-7656e63305b1.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=1a1045a1-bec1-45c7-97e9-f3c9f7937cc7</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,1a1045a1-bec1-45c7-97e9-f3c9f7937cc7.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,1a1045a1-bec1-45c7-97e9-f3c9f7937cc7.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=1a1045a1-bec1-45c7-97e9-f3c9f7937cc7</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>A Ruby Wishlist</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,1a1045a1-bec1-45c7-97e9-f3c9f7937cc7.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/04/21/ARubyWishlist.aspx</link>
      <pubDate>Wed, 21 Apr 2004 09:21:08 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is a Wish List for Ruby. Ruby is an excellent
language, however here are some small things that I would like to see added to Ruby:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;b&gt;Threading 
&lt;br&gt;
&lt;/b&gt;I wish ruby had real threads. The threading support currently provided is really
sad. If Rite could actually have OS threads as Ruby threads, like in the .Net framework
it would be awesome, instead of doing them as interpreter threads. Write now doing
any sort of meaningful multithreaded application in ruby is meaningless.&lt;br style="mso-special-character: line-break"&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;/div&gt;
&lt;b&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/b&gt;&gt;&gt; 
&lt;li&gt;
&lt;div class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;b&gt;C/C++
style operators&lt;br&gt;
&lt;/b&gt;I wish ruby had ++, --&amp;nbsp;operators. They really do not contribute to unmanageable
code and on the whole are nice things to have.&lt;br style="mso-special-character: line-break"&gt;
&lt;/div&gt;
&gt;&gt; 
&lt;li&gt;
&lt;div class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;b&gt;Use
of Curly Braces { }&lt;br&gt;
&lt;/b&gt;I wish that Ruby would let the usage of curly braces to define blocks of code
other than just parameter blocks that receive yield results. I would like to use {}
to enclose methods, classes, if statements, loops etc. 
&lt;br&gt;
&lt;br&gt;
Write now code that is written like:&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;span class=CodeSnippetCharChar&gt;&lt;font face="Courier New" color=#000000&gt;def
func(a)&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[1,2,3].each {|n|&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;if(n
% 2 == 0)&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
&amp;#8220;This is even&amp;#8221;&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
&amp;#8220;Odd&amp;#8221;&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
&amp;#8220;Multiple of 3&amp;#8221; if (n%3==0)&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;end&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;br&gt;
end&lt;/font&gt;&lt;/span&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;b&gt; 
&lt;br&gt;
&lt;br&gt;
&lt;/b&gt;being very C-ish in my ways I would really like it if I could avoid all those
clumsy ends. 
&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span class=CodeSnippetCharChar&gt;def
func(a) {&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;[1,2,3].each {|n|&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(n%2 == 0)&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print &amp;#8220;This
is even&amp;#8221;&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else {&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
&amp;#8220;Odd&amp;#8221;&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
&amp;#8220;Multiple of 3&amp;#8221; if (n%3==0)&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;}&lt;br&gt;
}&lt;/span&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;
&lt;br&gt;
These days since the Python bug has bitten a bit, I am warming up to the idea of scope
by indentation. 
&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font color=#000000&gt;&lt;span class=CodeSnippetCharChar&gt;&lt;font face="Courier New"&gt;def
func(a) 
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;[1,2,3].each |n|&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(n%2 == 0)&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print &amp;#8220;This
is even&amp;#8221;&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;else 
&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
&amp;#8220;Odd&amp;#8221;&lt;br&gt;
&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
&amp;#8220;Multiple of 3&amp;#8221; if (n%3==0)&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/span&gt;&lt;font face=Arial&gt;This actually looks quiet nice, but it may not be a
good think to have because such code often tends to get messed up real bad when you
copy paste it around and spoils the indentation. &lt;/font&gt;&lt;/font&gt;&lt;span class=CodeSnippetCharChar&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;/div&gt;
&gt;&lt;b&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/b&gt; 
&lt;li&gt;
&lt;div class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b&gt;Better
Win32Ole libraries&lt;br&gt;
&lt;/b&gt;This is something that I must have. I use scripting to be able to talk to WMI
(Windows Management Instrumentation). 
&lt;br&gt;
&lt;br&gt;
The libraries that Ruby ship for this is really sad. Very unstable. At the time of
this writing the current Ruby distribution has removed the win32ole libraries from
Ruby. I hope they will come back, stabler. 
&lt;br&gt;
&lt;br&gt;
The reason why Win32Ole is important to me is that it is the mechanism used to talk
to WMI and WMI can let you some really awesome stuff. 
&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting06112002.asp"&gt;&lt;font face=Arial&gt;WMI
Primer on MSDN&lt;/font&gt;&lt;/a&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;/div&gt;
&lt;b&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/b&gt; 
&lt;li&gt;
&lt;div class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;b&gt;Auto
Initialization of variables&lt;br&gt;
&lt;/b&gt;When I write code like this&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span class=CodeSnippetCharChar&gt;sum
= 0&lt;br&gt;
10.times{|n| sum = sum + n }&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Arial color=#000000&gt;I wish I need not have to initialize
&amp;#8216;sum&amp;#8217;. I wish there was some unambiguous way of saying that &amp;#8216;I know
sum hasn&amp;#8217;t been defined before, so please use its initial value as 
&lt;VALUE&gt;
&amp;#8217;. I would just like to be able to say 10.times {|n| sum = sum + n } and things
should just work, assuming that sum gets initialized as 0. I wish there was some shorthand
hand initializing a variable for its first appearance in an expression.&lt;br&gt;
&lt;br&gt;
Like I could probably replace:&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span class=CodeSnippetCharChar&gt;sum&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;=
0 
&lt;br&gt;
prod = 1&lt;br&gt;
10.times {|n| sum = sum + n; prod = prod * n }&lt;br&gt;
&lt;/span&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Arial color=#000000&gt;with&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span class=CodeSnippetCharChar&gt;10.times
{|n| sum = sum&amp;lt;0&amp;gt; + n; prod = prod&amp;lt;1&amp;gt; + n; }&lt;br&gt;
&lt;/span&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Arial color=#000000&gt;or better if I had support for C++ style
operators, I could write 
&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;span class=CodeSnippetCharChar&gt;&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;10.times{|n|
sum&amp;lt;0&amp;gt; += n; prod&amp;lt;1&amp;gt; *= n; }&lt;br&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;/div&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&gt;&gt;&gt; 
&lt;li&gt;
&lt;div class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; mso-bidi-font-weight: bold"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;b&gt;Run
on .Net&lt;br&gt;
&lt;/b&gt;I wish ruby could run on .Net. There are python variants that run on Java and
now Python is coming up for .Net (&lt;/font&gt;&lt;/font&gt;&lt;a href="/PermaLink,guid,5e20c741-9618-4f62-974d-174fee0d7daf.aspx"&gt;&lt;font face=Arial&gt;IronPython&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;).
Imagine the power of having the flexibility of Ruby with the power and expanse of
the .Net framework. 
&lt;br&gt;
&lt;br&gt;
Maybe more work needs to be done before this is possible. 
&lt;br style="mso-special-character: line-break"&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;/div&gt;
&lt;b&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/b&gt;&gt;&gt; 
&lt;li&gt;
&lt;div class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font color=#000000&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;&lt;b&gt;Currying
of Methods and Partial Evaluations&lt;br&gt;
&lt;/b&gt;I wish I could have currying/partial evaluation possible for ruby methods. 
&lt;br&gt;
In many functional languages, functions are defined like this:&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;span class=CodeSnippetCharChar&gt;&lt;font face="Courier New" color=#000000&gt;-
fn add x y = x + y&lt;br&gt;
&amp;gt; int -&amp;gt; int -&amp;gt; int&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/span&gt;&lt;font face=Arial color=#000000&gt;Consider the ML like code above. The
first line I have defines a function called &amp;#8216;add&amp;#8217; that takes x and y and
does x+y. The second line is what the interpreter echoes back to me about the function.&lt;br&gt;
&lt;br&gt;
It is simply is trying to say that the method consumes two integers and produces an
integer. The two integers how ever are not used up at one go, rather, they are used
up sequentially. First the integer x is taken and bound to the function and then the
value y.&lt;br&gt;
&lt;br&gt;
By being able to do that, we can define other function instances of add that have
one of the variables bound. 
&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;font color=#000000&gt;&lt;span class=CodeSnippetCharChar&gt;&lt;font face="Courier New"&gt;-
fn add10 = add 10&lt;br&gt;
- fn add5 = add 5&lt;br&gt;
- add10 2&lt;br&gt;
&amp;gt; 12&lt;br&gt;
- add5 2&lt;br&gt;
&amp;gt; 7&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/span&gt;&lt;font face=Arial&gt;This shows off some very powerful features of what
currying can do. Here add10 and add5 are created as new functions, but with the value
of x substituted as 10 and 5 respectively. Now we can treat add10 and add5 as proper
functions that take only one parameter.&amp;nbsp;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face=Arial color=#000000&gt;What these languages let us do is that
we can apply a subset of the parameters of a function and created a curried or partially
evaluated function instance. Such an instance can, if the runtime is optimizing enough,
already do all the processes possible in the code upfront. Whenever the remaining
parameters are supplied, it could just go on to complete the operations.&amp;nbsp;&lt;/font&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Imagine that the method we were calling is this 
&lt;br style="mso-special-character: line-break"&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippetChar style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;fn mult x y = 10 * x * y&lt;br style="mso-special-character: line-break"&gt;
&lt;br style="mso-special-character: line-break"&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;and then we wish to do &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippetChar style="MARGIN: 0in 0in 0pt"&gt;
&lt;br&gt;
&lt;font face="Courier New" color=#000000&gt;mult 10 2&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippetChar style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;mult 10 3&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippetChar style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;mult 10 4 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;These calls will now cause it to do 10 * 10 * 2, 10
* 10 * 3 and 10 * 10 * 4&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;However if we could partially evaluate a function we
could say&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippetChar style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;fn mult10 = mult 10&lt;br&gt;
mult10 2&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippetChar style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;mult10 3&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippetChar style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;mult10 4&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When mult10 is created it is already evaluated to being
&amp;#8220;100 * y&amp;#8221;. So, subsequent calls would cause it to do only 100 * 2, 100
* 3 and 100 * 4.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;To add this sort of support to Ruby will have to bring
large changes to the language. A simpler implementation would be to create a method
object (yes that&amp;#8217;s possible in Ruby) and also a hash of the partial list of
parameters. The call itself could be formally executed only when all formal parameters
are satisfied by the parameter hash table collection. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you are still reading this might interest you:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.svendtofte.com/code/curried_javascript/"&gt;&lt;font face=Arial&gt;http://www.svendtofte.com/code/curried_javascript/&lt;/font&gt;&lt;/a&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Whew!&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Well, that&amp;#8217;s about it for now. But as you can
see most of what I am asking for here are simple things and superficial changes. I
would however really like to see the win32ole, threads&amp;nbsp;and ++ operators in Ruby,
even if none of the others work out. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Matz, (Yukihiro Matsumoto), the creator of Ruby is
planning to introduce some significant changes to the language and more importantly
going to get it running off a formal virtual machine that he is writing for Ruby called
Rite.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here are some of the plans for Rite and Ruby:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;a href="http://www.rubygarden.org/ruby?Rite"&gt;http://www.rubygarden.org/ruby?Rite&lt;/a&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I found this on one of the websites, this is about
how Matz wanted to work on Rite:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/76588"&gt;&lt;font face=Arial&gt;http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/76588&lt;/font&gt;&lt;/a&gt;
&lt;br&gt;
&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;|* will Rite be developed publicly..
Or will you keep it souce secret?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;From my experience and
observation, an open source software needs to&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;have running code before
the ball rolling to success.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I think
I need to work alone until the first running version.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;|* still use Ruby license scheme?&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;It will be open source
software for sure.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;License terms may
be&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;changed.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;|* do you need help?&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Say
what we should do and we will do it :-)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;This is very important.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Listen
carefully.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;From the reason I stated
above, I feel like I will work alone.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;But if someone shows
his talent, and comes up with his own _good_&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;implementation of new
Ruby earlier than me, and if he is willing to&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;contribute his code,
and if he allows me to hack and chop his code to&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;make it "Rite", I will
name it "Rite".&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;And he will be honored
for ever.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=1a1045a1-bec1-45c7-97e9-f3c9f7937cc7" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,1a1045a1-bec1-45c7-97e9-f3c9f7937cc7.aspx</comments>
      <category>Languages</category>
      <category>Ruby</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=e5126078-543f-49bf-a83a-325c11ec7682</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,e5126078-543f-49bf-a83a-325c11ec7682.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,e5126078-543f-49bf-a83a-325c11ec7682.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=e5126078-543f-49bf-a83a-325c11ec7682</wfw:commentRss>
      <title>SICP, Fiber api and ITERATORS !(Part 4)</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,e5126078-543f-49bf-a83a-325c11ec7682.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/04/19/SICPFiberApiAndITERATORSPart4.aspx</link>
      <pubDate>Mon, 19 Apr 2004 12:48:40 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Last night we did it again. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;We went for this movie (50 First Dates) and came home
feeling a little giddish. I was feeling a little giddish before the movie after nearly
having my head ripped off sitting on a &lt;/font&gt;&lt;a href="http://www.hamindia.com/images/ham001.jpg"&gt;&lt;font face=Arial&gt;Torra
Torra&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;,
in a fair in 
&lt;st1:City&gt;
&lt;st1:place&gt;Bangalore&lt;/st1:place&gt;
&lt;/st1:City&gt;
. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So after the movie and the drive back home, what do
we decide to do, like the nice normal people we are? We decide that we need to drink
coffee at 
&lt;st1:time Minute="0" Hour="0"&gt;12am&lt;/st1:time&gt;
and discuss programming. So we head off to &lt;/font&gt;&lt;a href="http://www.theleela.com/leelabang/home.html"&gt;&lt;font face=Arial&gt;Leela
Palace&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; where there is a late night &lt;/font&gt;&lt;a href="http://www.barista.co.in/"&gt;&lt;font face=Arial&gt;Barista&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Something about the way coffee affects my head, when
drunk late at night, especially after a movie needs some investigation. &lt;/font&gt;&lt;a href="http://www.livejournal.com/users/mat_attack/"&gt;&lt;font face=Arial&gt;Sidharth&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; was
my comrade is arms, or rather comrade in coffee. So what do we do? we go there and
sit down and drink coffee and I start off on $g(SICP) (Structure and Interpretation
of Computer Programs) which I have been postponing for several years now. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I think part of why I was so adamant about starting
out on SICP in the middle of the night is that I feel life (like usual) isn&amp;#8217;t
going anywhere. It turns out that a lot of smart people at various Universities decided
that I was wasn&amp;#8217;t smart enough to warrant a formal higher education in Computer
Science and the place I want to be the most, doesn&amp;#8217;t seem to want me around
because of some technicality (for the fifth time). So since life wasn&amp;#8217;t going
anywhere, I figured I&amp;#8217;d just have teach myself the things I want to know, my
own way. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A little fast-forward in time and what finally ends
up happening is that Sidharth and I end up talking about a certain MSDN article. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;Implementing Coroutines for .NET by Wrapping
the Unmanaged Fiber API&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/03/09/CoroutinesinNET/default.aspx"&gt;&lt;span style="FONT-WEIGHT: normal"&gt;&lt;font face=Arial&gt;http://msdn.microsoft.com/msdnmag/issues/03/09/CoroutinesinNET/default.aspx&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;We ended up in a rather (heated) philosophic discussion
about how iterators could be implemented, till 
&lt;st1:time Minute="0" Hour="4"&gt;4am&lt;/st1:time&gt;
, which is what this blog entry is about. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you have been reading about iterators in my previous
blog entries&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="/CommentView,guid,dd0e61ef-6fb1-4156-9d16-81c20a6aa871.aspx"&gt;&lt;font face=Arial&gt;Iterators
in Ruby (Part - 1)&lt;/font&gt;&lt;/a&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="/CommentView,guid,02da61dd-1e35-4a36-b46b-aa3a605b2ad6.aspx"&gt;&lt;font face=Arial&gt;Warming
up to using Iterators (Part 2)&lt;/font&gt;&lt;/a&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Then the idea is probably growing on you already. What
Sidharth and I did is put in some thinking about how iterators could be implemented.
This entry is going to break the logical flow of these two articles, but I am letting
it be. I will probably have a part 3 post that will bridge the gap between Parts 1
and 2 and what I am going to say here about iterators. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Also, like a lot of things on this blog, I am not an
authority on the subject so I am just guessing at how these things actually work. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;Iterators&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The thing about iterators is that there are two functions
involved that have to maintain execution state at the same time. So example when a
function calls another function, the caller is frozen and the callee executes &amp;#8211;
so the caller maintains execution state during the run time of the callee. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def callee&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
1&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
2&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
3&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def caller &lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;callee
{ |n|&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;#parameter block to the iterator&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;puts n&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When the callee is an iterator, the control actual
leaves the callee and returns to the caller, when the execution is in the parameter
block of the iterator. However we don&amp;#8217;t see this sort of behavior in a normal
C stack. Why? because when a function on the C stack returns to the caller, the function&amp;#8217;s
activation record on the stack is destroyed. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;How do we do this? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The approach in the MSDN article uses an API called
the fiber API. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;Fiber Approach&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The fibers can the thought of as threads that don&amp;#8217;t
have the scheduler attached to them.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;So
unless a fiber is explicitly passed control it will not be executed, unlike a thread
which is invoked by scheduler for a time slice. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What Ajai Shankar (the author of the MSDN article)
does is use fibers to represent iterators. So in the above snippet, the function callee()
would actually execute on a different fiber from&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;caller.
So when control needs to shift to the parameter block, which is to be executed in
the caller() function, a fiber is a switch occurs. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When the parameter has finished execution a context
switch occurs again. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What further happens is that the author has wrapped
up all this dirty jumping around into a managed C++ class that invokes the OS api.
He then goes onto write C# code (really!) that uses yield, almost the same way Ruby
would use it. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;(pasted)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;class CorIter {&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;public
void Next() {&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;object[]
array = new object[] {1, 2, 3, 4};&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;for(int
ndx = 0; true; ++ndx)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Yield(arr[ndx]);&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you get the general idea, then lets move on. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The problems with using the fiber API, among other
problems, are&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Every
fiber is like a thread, which means that the more the iterators the more the number
of fiber specific stack frames and such that get created &amp;#8211; which means&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;more
the code bloat for code like this. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Using
the fiber api actually makes this a very OS specific solution &amp;#8211; other OSes that
the CLR may wish to target may not have provisions for building up such an API. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.1in; TEXT-INDENT: -0.1in; mso-list: l0 level1 lfo1; tab-stops: list .25in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&amp;#183;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Arial&gt;Exceptions:
exceptions in the windows world are strung to the TLS (Thread Local Storage) of the
thread of execution &amp;#8211; this may behave rather odd when fibers are mixed into
the picture. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Let ignore everything and just examine the first problem,
the issue of creating separate stack frames per fiber and thus bloating the system
&amp;#8211; if we could solve this one, then I think (and I might be wrong), would bring
more credit to this approach.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial&gt;&lt;font color=#000000&gt;
&lt;st1:place&gt;
&lt;st1:PlaceName&gt;
&lt;b&gt;Wrapping&lt;/b&gt;
&lt;/st1:PlaceName&gt;
&lt;b&gt;&lt;/b&gt;
&lt;st1:PlaceType&gt;
&lt;b&gt;State&lt;/b&gt;
&lt;/st1:PlaceType&gt;
&lt;/st1:place&gt;
&lt;b&gt; in a Caller Object&lt;o:p&gt;&lt;/o:p&gt;
&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One other approach to supporting iterators is to ensure
that one of the two functions (the caller or the callee) maintain state using some
mechanism other than the C stack. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Lets take a look at the caller:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def caller&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;callee
{ |n|&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;puts
n&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;or maybe a C# equivalent.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;void caller()&lt;br&gt;
{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;foreach(int
n in callee())&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine(n);&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This method can actually be though off as consisting
of three parts &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;void caller()&lt;br&gt;
{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;PART 1&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;foreach(int
n in callee())&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;PART 2&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Console.WriteLine(n);&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;PART 3&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;We could create an object to hold the state of the
function that would hold these three parts. Something like this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;class caller_object&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;//declare
all local variable so the class as member variables here&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;void
do_part1()&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;void do_codeblock() //part 2&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;void do_part3()&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The idea is that we create an object that has member
variables that represent the local variable of the caller.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;So
we execute the caller as three parts&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;void caller()&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;caller_object
co = new caller_object()&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;co.do_part1();&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;callee(co);&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;co.do_part3();&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The caller method now is simply a wrapper around the
class that represents the caller function as an object. When the method do_part1()
is called on the class, the object will have the same state as the original caller()
function when it has just run till the point where the iterator is invoked.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Then the callee() is invoked and the object that represents
the caller&amp;#8217;s state is passed to the callee. The callee then goes on to invoke
the object&amp;#8217;s do_codeblock() every time a yield is required. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Since the callee never returns till it has completed
execution it maintains state on the runtime stack, like a normal function. The do_codeblock()
has the same code that the code block of the for each loop had and it can also maintain
any state changes into the object. Finally when the callee() exits the object&amp;#8217;s
do_part3() is invoked. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is similar to what the iterators accomplish. Here
the state is stored in an object and not on the stack. However, here a full managed
type that represents that caller has to be created. I didn&amp;#8217;t like that too much. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;
&lt;st1:place&gt;
&lt;st1:PlaceName&gt;
&lt;b&gt;Wrapping&lt;/b&gt;
&lt;/st1:PlaceName&gt;
&lt;b&gt;&lt;/b&gt;
&lt;st1:PlaceType&gt;
&lt;b&gt;State&lt;/b&gt;
&lt;/st1:PlaceType&gt;
&lt;/st1:place&gt;
&lt;b&gt; in a Callee Object&lt;o:p&gt;&lt;/o:p&gt;
&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is similar to the above approach, except that
roles are reversed. We create an object that can represent the callee. The callee
then returns to the caller at every yield statement. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The callee state is maintained in the object representing
it. There is an excellent write up you can read about a similar approach here:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial&gt;&lt;span style="COLOR: black"&gt;Coroutines in C&lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;a href="http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html"&gt;&lt;font face=Arial&gt;http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The idea there is that the state of the function is
retained in a state variable. The state variable is used to jump back to the point
where the function had previously yielded from. Code would look a little like this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;(pasted)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;int function(void) {&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;static
int i, state = 0;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;switch
(state) {&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;case
0: /* start of function */&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;for
(i = 0; i &amp;lt; 10; i++) {&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;state
= 1; /* so we will come back to "case 1" */&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;return
i;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;case
1: /* resume control straight after the return */&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now this example uses static variables but it is easy
to imagine this being extended such that each variable is the member of some object.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;(pasted)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;It's a little bit ugly, because suddenly you
have to use ctx-&amp;gt;i as a loop counter where you would previously just have used
i; virtually all your serious variables become elements of the coroutine context structure.
But it removes the problems with re-entrancy, and still hasn't impacted the structure
of the routine.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;(Kudos to &lt;/font&gt;&lt;a href="http://dolly.thinkingms.com/"&gt;&lt;font face=Arial&gt;Pooja&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt;,
for coming up with this idea at one sitting).&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When C# announced the coming of iterators in the language
and a new yield keyword, I was excited. In the mood of the MSN co-routines article,
I had expected a CLR level support for iterators. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;It turns out that the C# teams approach is similar
to that of the saving the callee state in an object. (I am not very sure about whether
its the caller or the callee, in case I am wrong in assuming that it&amp;#8217;s the callee,
which seems to be the more logical choice, I will blog about it). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In the &lt;/font&gt;&lt;a href="http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html"&gt;&lt;font face=Arial&gt;Co-routines
in C&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; article, the author talks of writing
macros that wraps up the behavior. &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;Since
the compiler does the temporary object creation and hides all the mess from you, in
the case of C#, it seems like a reasonable alternative. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font color=#000000&gt;&lt;font face=Arial&gt;A modified form of the Fiber API idea&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The reason I don&amp;#8217;t really like the way C# does
iterators right now is because it is a hack. They did not want to change the CLR for
a feature that may not catch on. So I guess, they used a less expensive approach.
If I am wrong, I would like to be corrected. I would expect that more serious CLR
level support will come up for iterators if the idea&amp;#8217;s introduced in Whidbey
C# become popular.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The other reason I don&amp;#8217;t really like the approach,
the real reason, is that the .Net type system is a fairly comprehensive type system
designed to propagate an idea of types as a level playing field for language agnostic
components to interact. Introducing a type into the system just to retain a function&amp;#8217;s
state does not seem consistent with this philosophy. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Fiber API on the other hand more naturally lend themselves
to the way I would choose to think of iterators &amp;#8211; as functions that can be frozen
during execution and be continued. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now this might seem like a weak argument, but it seems
to better to use the processors abilities to do a context switch to actually freeze
execution of a block of code, that write the code as code that manages members of
an object (only for the purpose that the object can be used to retain the state of
the code). &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The Fiber API like approach seemed to do this more
naturally. I would expect that the CLR in future would internally provide some API
similar to that of the OS provided fibers so that it can do iterators and closures
and probably even continuations. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Some basic requirements would be that implementing
such features don&amp;#8217;t slow down execution of code that don&amp;#8217;t require any
of these features. Such features should be reasonably efficient with respect time
as well as space.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Let me try and discuss the space issues here. In fiber
API there would be need for creating totally new independent stack frames for each
fiber. This is wasteful.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Would it be possible so that we have a modified API,
which will behave like fibers, share stack space with the common C stack and can use
the processor context switching abilities to freeze function execution, rather than
save state as a managed object.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;A little bit of brainstorming last night and we had
this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In the .Net world, we have the luxury of being able
to predict the stack usage of a function under execution with IL directives like &amp;#8220;.maxstack&amp;#8221;.
Which is to say - we know how much space the function will use on the managed stack. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The stack frame for regular method calls would look
like this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt" align=center&gt;
&lt;img height=226 src="content/binary/iterator_stackframe1.gif" width=192 border=0&gt;&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;img height=235 src="content/binary/iterator_stackframe2.gif" width=193 border=0&gt;&amp;nbsp;&lt;img height=181 src="content/binary/iterator_stackframe3.gif" width=193 border=0&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This is obvious for anyone who understands how methods
are laid out on the stack. The only advantage that we have here is that in the .Net
world. We know exactly how much stack space a given method will use. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now if the method calls an iterators that has a yield,
we create a Fiber, but a special sort that would use the main stack itself as its
stack frame. So the newly created method instance (the iterator itself) will reside
on the call stack, above the caller. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;img height=247 src="content/binary/iterator_stackframe4.gif" width=198 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now the usual semantics of stack usage are allowed
on this fiber. The fiber behaves like any other thread would behave, owning the stack.
To allow methods to keep track of their callee&amp;#8217;s we add a reference to the activation
record of the callee. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;img height=250 src="content/binary/iterator_stackframe5.gif" width=198 border=0&gt;&lt;font face=Verdana color=#003300&gt;&amp;nbsp;&lt;img height=313 src="content/binary/iterator_stackframe6.gif" width=199 border=0&gt;&amp;nbsp;&lt;img height=247 src="content/binary/iterator_stackframe7.gif" width=198 border=0&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The interesting part, when the iterator needs to yield
a value. When it does control is switched back to the original fiber. The activation
record of the iterator is still maintained on the stack. Further method calls would
however place their activation records above the iterator&amp;#8217;s activation and behave
as though it was normal C stack. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;img height=304 src="content/binary/iterator_stackframe9.gif" width=199 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: center" align=center&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Thus I think it is possible to have fiber API like
constructs to implement iterators, share stack space have reasonably efficient implementations
too. The only real over head introduced here is a level of indirection when activation
records are torn down from the stack frame. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I feel that this is a more co-routine like approach
that the one that involves creating hidden managed objects. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I would like to wish that this idea can be extended
to implement proper continuations also, that is not very easy. Here the stack management
is very easy because as any point a sleeping fiber will contain only one activation
record on the stack. A continuation will require that activation objects live and
die on the manage stack as though they were proper objects and some sort of garbage
collection routine will be required on the stack. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;I am extremely open to opinions about this entry, because
I am treading on many areas that I am not very well versed with. I am hoping that
the idea of freezing execution state via fiber like constructs is more efficient that
the approach that involves creating full managed objects. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=e5126078-543f-49bf-a83a-325c11ec7682" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,e5126078-543f-49bf-a83a-325c11ec7682.aspx</comments>
      <category>Languages</category>
      <category>Mish Mash</category>
      <category>Programming</category>
      <category>Ruby</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=02da61dd-1e35-4a36-b46b-aa3a605b2ad6</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,02da61dd-1e35-4a36-b46b-aa3a605b2ad6.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,02da61dd-1e35-4a36-b46b-aa3a605b2ad6.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=02da61dd-1e35-4a36-b46b-aa3a605b2ad6</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>Warming up to using Iterators (Part 2)</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,02da61dd-1e35-4a36-b46b-aa3a605b2ad6.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/04/16/WarmingUpToUsingIteratorsPart2.aspx</link>
      <pubDate>Fri, 16 Apr 2004 08:28:18 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In the past article &lt;/font&gt;&lt;a href="/PermaLink,guid,dd0e61ef-6fb1-4156-9d16-81c20a6aa871.aspx"&gt;&lt;font face=Arial&gt;Iterators
in Ruby (Part - 1)&lt;/font&gt;&lt;/a&gt;&lt;font face=Arial color=#000000&gt; I talked about the concept
of iterators and how iterators are available in Ruby. In this part I&amp;nbsp;will dwell
on&amp;nbsp;how iterators are used, so that the concept grows on you.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;For someone used to the C/C++ world, the constructs
provided by those languages suffice to express any idea of their choosing. While that
is true, programming in a C-like language causes us to close our minds to other styles
of programming and other constructs that might exist. Programming in C after a point
is about writing the next big program optimized with lots of data-structure usage
and trying to tie&amp;nbsp;a new algorithm down into C. Sometimes the joy of programming,
where the language lets you do your job - express ideas as code, is lost. Sometimes
we spend our time servicing our language syntax and spoon-feeding our compilers. The
fact that languages might actually evolve so that you can get on with your job, was
alien for a long time to me. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;If you have read the first part you might be wondering
how iterators are used in Ruby. Admittedly, the idea would seem a little complex and
maybe contrived to the uninitiated. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In Ruby, iterators are used pervasively. Its there
all over the place and once you get started on Ruby,&amp;nbsp;you will probably end up
using an iterator without realizing that you are using one. The Ruby libraries are
rich with iterators of various sorts. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;Simple Loops&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;When you start of on Ruby code, you might see loops
of the sort:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;10.times {&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
&amp;#8220;hello world&amp;#8221;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;This, as you might expect, prints &amp;#8216;hello world&amp;#8217;
10 times. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;How does this work? Ruby is a pure object oriented
language. The number 10 is an integer, and the integer class exposes a method called
&amp;#8216;times&amp;#8217;. The times method is an iterators that yields values from 0 to
its value -1.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Since it yields values, can we catch them ? Yes. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;10.times {|n|&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
n&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;And this prints all the values from 0 to n-1. 
&lt;br&gt;
'times' is an iterator.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;File Handling&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Let&amp;#8217;s look at some file handling in Ruby. The
following&amp;nbsp;code&amp;nbsp;will open a file and read each line of the&amp;nbsp;file and
print the line among with its line number. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;file = File.new(&amp;#8220;filename.txt&amp;#8221;)&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;c = 0&lt;br&gt;
file.each_line {|line|&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;c
= c + 1&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
&amp;#8220;#{c}: #{line}&amp;#8221;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The code is simple. I open a file and create a file
object. I ask the object to yield each line to me. As I get each line I print it out
along with the line number. This is as logically expressive as I have seen in any
language that I have used. All the mess stays out of your way and you get to focus
on the job at hand. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The each_line is a method of the File class and it
yields each line in&amp;nbsp;the file. The variable &amp;#8216;line&amp;#8217; will hold the value
of each line. Slick? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;(I you are wondering what &amp;#8220;#{c}: #{line}&amp;#8221;
means &amp;#8211; in a string #{ } is a substitution. You can write any expression into
the curly braces. Here the values of c and line get substituted into the string)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;Arrays / Collections&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Similarly collection types expose an &amp;#8220;each&amp;#8221;
method which yields every member of the collection. So if I had to iterate over an
array I would write:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;array = [1,2,3,4]&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;array.each {|m| puts m }&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The above code creates an array of 4 elements and accesses
each element using the iterator &amp;#8220;each&amp;#8221;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;In similar fashion, a lot of the Ruby library exposes
functionality as iterators. So much so, that I rarely write for loops in Ruby. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;b&gt;&lt;font face=Arial&gt;&lt;font color=#000000&gt;Recursive Directory Enumeration&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now let us try and write code of our own. Something
you may all have written is code that will find all the text files in a folder and
is sub folders. The usual approach is to write a recursive function. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The function will try and remember a list of text files,
in the current directory and the list of sub directories it has. It will then recursively
call each of the subdirectories, each of which will do the same task. The problem
is that if every time a text file is to be found, some processing is to be done, things
get very complicated. The usual approach is&amp;nbsp;to find&amp;nbsp;all the text files and
create a big list of filenames, which is then processed later.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Here is an&amp;nbsp;approach with iterators. Try and implement
this in your favorite language that does not have iterators and see how it looks. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;def textfiles(dir)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Dir.chdir(dir)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Dir["*"].each
do |entry|&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
dir+"\\"+entry if /^.*\.txt$/ =~ entry&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;if
FileTest.directory?(entry)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;textfiles(entry){|file|
yield dir+"\\"+file}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;end 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Dir.chdir("..")&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;end&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;textfiles(&amp;#8220;c:\\&amp;#8221;){|file|&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;puts
file&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What the above code does is simple. I have defined
a method called textfiles() that takes a directory name as a parameter. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The code looks exactly like you would explain it algorithmically. &lt;/font&gt;
&lt;/p&gt;
&lt;ol style="MARGIN-TOP: 0in" type=1&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font face=Arial color=#000000&gt;Go to the folder (chdir)&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font face=Arial color=#000000&gt;Take a look at the contents (Dir[&amp;#8220;*&amp;#8221;])&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;See is an entry is a text file, if so yield it
(&lt;/font&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;yield dir+"\\"+entry if /^.*\.txt$/
=~ entry&lt;/span&gt;&lt;font face=Arial&gt;)&lt;span style="FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;See is an entry is a directory, if so, recurse
into it 
&lt;br&gt;
(&lt;/font&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;if FileTest.directory?(entry)&lt;br&gt;
&lt;/span&gt;&lt;/font&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;textfiles(entry){|file|
yield dir+"\\"+file}&lt;br&gt;
&lt;/font&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font color=#000000&gt;end)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;span style="FONT-FAMILY: 'Courier New'"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Simple?&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Notice
that the beauty of code is that the yield actually sends the value of a filename down
a recursive hierarchy.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;As a disclaimer, if you are using Ruby, then you might
a well finish off in one line by saying:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;
&lt;br&gt;
Dir[&amp;#8220;**/*.txt&amp;#8221;].each{|file| puts file }&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=02da61dd-1e35-4a36-b46b-aa3a605b2ad6" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,02da61dd-1e35-4a36-b46b-aa3a605b2ad6.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
      <category>Ruby</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=ec93a91f-c49b-46b2-9ded-d5f43e49d9a8</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,ec93a91f-c49b-46b2-9ded-d5f43e49d9a8.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,ec93a91f-c49b-46b2-9ded-d5f43e49d9a8.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=ec93a91f-c49b-46b2-9ded-d5f43e49d9a8</wfw:commentRss>
      <title>First article about the DDL published</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,ec93a91f-c49b-46b2-9ded-d5f43e49d9a8.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/04/15/FirstArticleAboutTheDDLPublished.aspx</link>
      <pubDate>Thu, 15 Apr 2004 06:35:38 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;&lt;font face=Arial&gt;I finally got copies of my first article published
about the DDL. The article was published in the .Net Developer Journal. 
&lt;br&gt;
&lt;a href="http://www.sys-con.com/dotnet/"&gt;http://www.sys-con.com/dotnet/&lt;/a&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The DDL was a language that my team developed during
our final year college project. At that time, we believed that it was a one of a kind
language. Of late we have come across similar work done by Professor Godmar Back of
Stanford University.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The DDL language basically lets one specify binary
data formats and the language interpreter provides services to interact with data
of that format. Read more about the DDL at the project homepage:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;a href="http://ddl.sscli.net/"&gt;http://ddl.sscli.net/&lt;/a&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Professor Godmar Back&amp;#8217;s DataScript language is
described here:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;a href="http://datascript.sourceforge.net/"&gt;http://datascript.sourceforge.net/&lt;/a&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=1&gt;Apr 14 2004 Wednesday 01-24PM&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=ec93a91f-c49b-46b2-9ded-d5f43e49d9a8" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,ec93a91f-c49b-46b2-9ded-d5f43e49d9a8.aspx</comments>
      <category>DDL</category>
      <category>Languages</category>
      <category>Programming</category>
    </item>
    <item>
      <trackback:ping>http://www.thinkingms.com/pensieve/Trackback.aspx?guid=dd0e61ef-6fb1-4156-9d16-81c20a6aa871</trackback:ping>
      <pingback:server>http://www.thinkingms.com/pensieve/pingback.aspx</pingback:server>
      <pingback:target>http://www.thinkingms.com/pensieve/PermaLink,guid,dd0e61ef-6fb1-4156-9d16-81c20a6aa871.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.thinkingms.com/pensieve/CommentView,guid,dd0e61ef-6fb1-4156-9d16-81c20a6aa871.aspx</wfw:comment>
      <wfw:commentRss>http://www.thinkingms.com/pensieve/SyndicationService.asmx/GetEntryCommentsRss?guid=dd0e61ef-6fb1-4156-9d16-81c20a6aa871</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <title>Iterators in Ruby (Part - 1)</title>
      <guid isPermaLink="false">http://www.thinkingms.com/pensieve/PermaLink,guid,dd0e61ef-6fb1-4156-9d16-81c20a6aa871.aspx</guid>
      <link>http://www.thinkingms.com/pensieve/2004/04/15/IteratorsInRubyPart1.aspx</link>
      <pubDate>Thu, 15 Apr 2004 06:31:50 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One of the things that&amp;#8217;s rather high on my mind&amp;#8217;s
sort order these days is Ruby programming. I have been thinking about what makes ruby
so neat a language to use, simply by virtue of what the language lets me do.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;One of the early things that got me hooked to Ruby,
was its support for &lt;b&gt;iterators&lt;/b&gt;. If you have been spoiled by many years of C
programming, like me, then its time to wake up and take a look at a few things that
C can&amp;#8217;t pull off, at least not very easily. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What is an iterator? &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Let&amp;#8217;s take a look at code like this, where there
is a piece of code that produces value and a piece of code that consumes values. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;void produce()&lt;br&gt;
{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;for (int i=0;i&amp;lt;100;i++)&lt;br&gt;
&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if(
i%5 == 0)&lt;br&gt;
&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;consumer(i);&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;void consumer(int v)&lt;br&gt;
{&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"&gt;
&lt;font face="Courier New" color=#000000&gt;printf(&amp;#8220;%d&amp;#8221;,v);&lt;br&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;All things considered this code is fine, except that
the producer invokes the consumer. And simply because of that the consumer cannot
maintain state. The only way the consumer can maintain state, ie remember something
between two calls is to save variables into either static variables, or globals or
into some object.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The would be the argument if the consumer function
tried invoking the producer, where the producer will have to have a very contrived
piece of code to remember variable values between calls. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;From a perspective, an iterator solves exactly this
problem. This is a ruby code:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def producer&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;for
i in 0..99&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;if
(i%5 == 0)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;yield
i&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;end&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;end&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def consumer&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;producer()
do |v| &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
v&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;end&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The &amp;#8216;def&amp;#8217; keyword starts a function/method
declaration. The code above for the producer should be rather easy to understand,
except for the yield statement. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;What does the yield do? The yield causes the function
producer() to exit with the return value of the function as the parameter of the yield,
in this case &amp;#8216;i&amp;#8217;. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The difference between yielding a value and actually
doing a return is that the function can continue execution from the point of the yield
statement. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The consumer function then simply invokes the producer()
function and catches each of the yielded values. That is why these is a &amp;#8216;do&amp;#8217;
statement and a corresponding &amp;#8216;end&amp;#8217; statement in the consumer code. The
parameter for the do-end block is the &amp;#8216;v&amp;#8217; that is enclosed in ||. Every
time the producer yields a value, the value is available in &amp;#8216;v&amp;#8217; and the
do-end block is executed. When the block finishes the producer continues after the
point of the yield.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;So if you want to, say calculate the sum of all the
values that the producer yields, then you can &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def consumer&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sum
= 0&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;producer()
do |v|&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sum
= sum + v&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;end&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
sum&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now that you have been introduced to the idea of iterators,
I suggest you do some thinking about, especially if you have done a fair bit of C
programming. Imagine how these functions would have to maintain state, what their
call stacks will look like and such.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;Now let me clean up on a few things. In ruby all functions
are called methods, formally. So let&amp;#8217;s start calling them methods. Secondly
a lot of the Ruby libraries are built to support iterators so you will see the idea
being used a lot. Thirdly, the do-end block can also be written as { } curly braces. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;The methods that I have written have been written in
a drawn out C-like style, so that the ideas are clear despite the slight difference
in syntax. So lets just rewrite the two methods slightly more ruby-ishly and close
this blog entry.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def producer&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;100.times{|i|
yield i if i%5 == 0}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face="Courier New" color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;def consumer&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sum
= 0&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;producer
{|v| sum = sum + v}&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New"&gt;&lt;font color=#000000&gt;&lt;span style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;print
sum&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=CodeSnippet style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face="Courier New" color=#000000&gt;end&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Arial color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;You can get Ruby from here, for your windows box:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Arial color=#000000&gt;&lt;a href="http://rubyinstaller.sourceforge.net"&gt;http://rubyinstaller.sourceforge.net&lt;/a&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=1&gt;Apr 13 2004 Tuesday 11-05AM&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.thinkingms.com/pensieve/aggbug.ashx?id=dd0e61ef-6fb1-4156-9d16-81c20a6aa871" /&gt;</description>
      <comments>http://www.thinkingms.com/pensieve/CommentView,guid,dd0e61ef-6fb1-4156-9d16-81c20a6aa871.aspx</comments>
      <category>Languages</category>
      <category>Programming</category>
      <category>Ruby</category>
    </item>
  </channel>
</rss>