<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>porges</title>
	<atom:link href="http://porg.es/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://porg.es/blog</link>
	<description>... master of none</description>
	<lastBuildDate>Mon, 30 Nov 2009 22:04:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Back in Auckland</title>
		<link>http://porg.es/blog/back-in-auckland</link>
		<comments>http://porg.es/blog/back-in-auckland#comments</comments>
		<pubDate>Mon, 30 Nov 2009 22:04:58 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[self]]></category>
		<category><![CDATA[Me]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=412</guid>
		<description><![CDATA[&#8230; and looking for employment, if anyone wants to hire me 
]]></description>
			<content:encoded><![CDATA[<p>&#8230; and looking for employment, if anyone wants to hire me <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/back-in-auckland/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>n-pivot quicksort</title>
		<link>http://porg.es/blog/n-pivot-quicksort</link>
		<comments>http://porg.es/blog/n-pivot-quicksort#comments</comments>
		<pubDate>Sat, 12 Sep 2009 07:56:15 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[Functional programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[quicksort]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=392</guid>
		<description><![CDATA[2-pivot quicksort
This posting on the Java core library mailing list proposes to replace the current quicksort with a new, 2-pivot quicksort.
Ordinary quicksort in Haskell looks something like this:

quicksort &#91;&#93; = &#91;&#93;
quicksort &#40;pivot:rest&#41; =
   quicksort &#91;x&#124; x ← rest, x ≤ pivot&#93; ++
   &#91;pivot&#93; ++
   quicksort &#91;x&#124; x ← rest, [...]]]></description>
			<content:encoded><![CDATA[<h3>2-pivot quicksort</h3>
<p>This <a href="http://permalink.gmane.org/gmane.comp.java.openjdk.core-libs.devel/2628">posting on the Java core library mailing list</a> proposes to replace the current quicksort with a new, 2-pivot quicksort.</p>
<p>Ordinary quicksort in Haskell looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">quicksort <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
quicksort <span style="color: green;">&#40;</span>pivot:rest<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span>
   quicksort <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">|</span> x ← rest<span style="color: #339933; font-weight: bold;">,</span> x ≤ pivot<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span>
   <span style="color: green;">&#91;</span>pivot<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span>
   quicksort <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">|</span> x ← rest<span style="color: #339933; font-weight: bold;">,</span> x <span style="color: #339933; font-weight: bold;">&gt;</span> pivot<span style="color: green;">&#93;</span></pre></div></div>

<p>Note the similarity of this to the notation for &#8216;invariants&#8217; used in the email:</p>
<pre>[ <= p | >= p ]</pre>
<p>Similarly, for the 2-pivot invariants (I have corrected a typo in this):</p>
<pre>[ < P1 | P1 <= &#038; <= P2 | > P2 ]</pre>
<p>We can derive the code:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">quicksort2 <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
quicksort2 <span style="color: green;">&#40;</span>only:<span style="color: green;">&#91;</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span>only<span style="color: green;">&#93;</span>
quicksort2 <span style="color: green;">&#40;</span>first:second:rest<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span>
   quicksort2 <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">|</span>x ← rest<span style="color: #339933; font-weight: bold;">,</span> x <span style="color: #339933; font-weight: bold;">&lt;</span> p1<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span>
   <span style="color: green;">&#91;</span>p1<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span>
   quicksort2 <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">|</span>x ← rest<span style="color: #339933; font-weight: bold;">,</span> p1 ≤ x <span style="color: #339933; font-weight: bold;">&amp;&amp;</span> x ≤ p2<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span>
   <span style="color: green;">&#91;</span>p2<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span>
   quicksort2 <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">|</span>x ← rest<span style="color: #339933; font-weight: bold;">,</span> p2 <span style="color: #339933; font-weight: bold;">&lt;</span> x<span style="color: green;">&#93;</span>
  <span style="color: #06c; font-weight: bold;">where</span> <span style="color: green;">&#40;</span>p1<span style="color: #339933; font-weight: bold;">,</span>p2<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">if</span> first ≤ second <span style="color: #06c; font-weight: bold;">then</span> <span style="color: green;">&#40;</span>first<span style="color: #339933; font-weight: bold;">,</span>second<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">else</span> <span style="color: green;">&#40;</span>second<span style="color: #339933; font-weight: bold;">,</span>first<span style="color: green;">&#41;</span></pre></div></div>

<p>Which does, in fact, run faster than the ordinary 1-pivot quicksort.</p>
<h3><i>n</i>-pivot quicksort</h3>
<p>Of course, this being Haskell we want to take things to their logical conclusions, and allow any number of pivots to be used. My formulation follows:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">quicksortN <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
quicksortN <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span>x:<span style="color: green;">&#91;</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span>x<span style="color: green;">&#93;</span>
quicksortN n xs
    <span style="color: #339933; font-weight: bold;">|</span> n <span style="color: #339933; font-weight: bold;">&gt;</span> <span style="font-weight: bold;">length</span> xs <span style="color: #339933; font-weight: bold;">=</span> quicksortN <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>n `<span style="font-weight: bold;">div</span>` <span style="color: red;">2</span><span style="color: green;">&#41;</span> `<span style="font-weight: bold;">max</span>` <span style="color: red;">1</span><span style="color: green;">&#41;</span> xs
    <span style="color: #339933; font-weight: bold;">|</span> <span style="font-weight: bold;">otherwise</span> <span style="color: #339933; font-weight: bold;">=</span> part True pivots
    <span style="color: #06c; font-weight: bold;">where</span>
      <span style="color: green;">&#40;</span>takexs<span style="color: #339933; font-weight: bold;">,</span>dropxs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">splitAt</span> n xs
      pivots <span style="color: #339933; font-weight: bold;">=</span> quicksortN <span style="color: red;">1</span> takexs
      part False <span style="color: green;">&#40;</span>p2:<span style="color: green;">&#91;</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span>      <span style="color: #339933; font-weight: bold;">=</span> quicksortN n <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">|</span>x ← dropxs<span style="color: #339933; font-weight: bold;">,</span> p2 <span style="color: #339933; font-weight: bold;">&lt;</span> x<span style="color: green;">&#93;</span>
      part False <span style="color: green;">&#40;</span>p1:p2:rest<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> quicksortN n <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">|</span>x ← dropxs<span style="color: #339933; font-weight: bold;">,</span> p1 <span style="color: #339933; font-weight: bold;">&lt;</span> x <span style="color: #339933; font-weight: bold;">&amp;&amp;</span> x ≤ p2<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#91;</span>p2<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span> part False <span style="color: green;">&#40;</span>p2:rest<span style="color: green;">&#41;</span>
      part True  <span style="color: green;">&#40;</span>p1:<span style="color: green;">&#91;</span><span style="color: green;">&#93;</span><span style="color: green;">&#41;</span>      <span style="color: #339933; font-weight: bold;">=</span> quicksortN n <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">|</span>x ← dropxs<span style="color: #339933; font-weight: bold;">,</span> x ≤ p1<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#91;</span>p1<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span> quicksortN n <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">|</span>x ← dropxs<span style="color: #339933; font-weight: bold;">,</span> p1 <span style="color: #339933; font-weight: bold;">&lt;</span> x<span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- remember me? :)</span>
      part True  <span style="color: green;">&#40;</span>p1:p2:rest<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> quicksortN n <span style="color: green;">&#91;</span>x<span style="color: #339933; font-weight: bold;">|</span>x ← dropxs<span style="color: #339933; font-weight: bold;">,</span> x ≤ p1<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#91;</span>p1<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span> part False <span style="color: green;">&#40;</span>p1:p2:rest<span style="color: green;">&#41;</span></pre></div></div>

<p>Now there are only 3 things that I can see that are left &#8216;tweakable&#8217;;</p>
<ul>
<li>how to reduce &#8216;n&#8217; when it is greater than length of the list</p>
<ul>
<li>dividing by 2 here</li>
</ul>
</li>
<li>how to sort the pivots
<ul>
<li>using a recursive call to the 1-pivot version of itself here</li>
</ul>
</li>
<li>whether or not to reduce the number of pivots as sorting continues
<ul>
<li>&#8216;no&#8217; chosen here</li>
</ul>
</li>
</ul>
<p>I have no idea whether these are sensible defaults <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
<h3>Which <i>n</i> should I choose?</h3>
<p>Finally, some code for the timings. You&#8217;ll need <a href="http://hackage.haskell.org/package/timeit">timeit</a> to run it.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
 gen ← getStdGen
 <span style="color: #06c; font-weight: bold;">let</span> n <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">10</span><span style="color: #339933; font-weight: bold;">^</span><span style="color: red;">6</span>
 <span style="color: #06c; font-weight: bold;">let</span> r <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">take</span> n <span style="color: #339933; font-weight: bold;">$</span> randoms gen <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span><span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: green;">&#93;</span>
 <span style="font-weight: bold;">print</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">sum</span> r <span style="color: #5d478b; font-style: italic;">-- force list</span>
 timeIt <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;quicksort = &quot;</span><span style="color: #339933; font-weight: bold;">++</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">show</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">sum</span> <span style="color: #339933; font-weight: bold;">$</span> quicksort r
 timeIt <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;quicksort2 = &quot;</span><span style="color: #339933; font-weight: bold;">++</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">show</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">sum</span> <span style="color: #339933; font-weight: bold;">$</span> quicksort2 r
 <span style="font-weight: bold;">mapM_</span> <span style="color: green;">&#40;</span>\x → timeIt <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;quicksortN &quot;</span><span style="color: #339933; font-weight: bold;">++</span> <span style="font-weight: bold;">show</span> x<span style="color: #339933; font-weight: bold;">++</span><span style="background-color: #3cb371;">&quot; = &quot;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">++</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">show</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">sum</span> <span style="color: #339933; font-weight: bold;">$</span> quicksortN x r<span style="color: green;">&#41;</span>
    <span style="color: green;">&#91;</span>1<span style="color: #339933; font-weight: bold;">..</span>20<span style="color: green;">&#93;</span></pre></div></div>

<p>Sample output:</p>
<pre>$ ./sort
858124546
quicksort = 858124546
CPU time:   4.60s
quicksort2 = 858124546
CPU time:   3.66s
quicksortN 1 = 858124546
CPU time:   5.19s
quicksortN 2 = 858124546
CPU time:   3.77s
quicksortN 3 = 858124546
CPU time:   3.28s
quicksortN 4 = 858124546
CPU time:   3.27s
quicksortN 5 = 858124546
CPU time:   3.06s
quicksortN 6 = 858124546
CPU time:   3.04s
quicksortN 7 = 858124546
CPU time:   3.04s
quicksortN 8 = 858124546
CPU time:   3.07s
quicksortN 9 = 858124546
CPU time:   3.10s
quicksortN 10 = 858124546
CPU time:   3.14s
quicksortN 11 = 858124546
CPU time:   3.22s
quicksortN 12 = 858124546
CPU time:   3.31s
quicksortN 13 = 858124546
CPU time:   3.30s
quicksortN 14 = 858124546
CPU time:   3.37s
quicksortN 15 = 858124546
CPU time:   3.54s
quicksortN 16 = 858124546
CPU time:   3.41s
quicksortN 17 = 858124546
CPU time:   3.52s
quicksortN 18 = 858124546
CPU time:   3.65s
quicksortN 19 = 858124546
CPU time:   3.63s
quicksortN 20 = 858124546
CPU time:   3.77s
</pre>
<p>As expected, generalized quicksort performs slower than the equivalent hard-coded quicksorts for specific values of <i>n</i>, but higher values of <i>n</i> than 1 or 2 can perform better.</p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/n-pivot-quicksort/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Debugging Turing: An excursion with Scheme</title>
		<link>http://porg.es/blog/debugging-turing-an-excursion-with-scheme</link>
		<comments>http://porg.es/blog/debugging-turing-an-excursion-with-scheme#comments</comments>
		<pubDate>Sun, 09 Aug 2009 15:07:55 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Functional programming]]></category>
		<category><![CDATA[ikarus]]></category>
		<category><![CDATA[machine]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[silly]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[turing]]></category>
		<category><![CDATA[universal]]></category>
		<category><![CDATA[ypsilon]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=368</guid>
		<description><![CDATA[So, I thought it would be a fun idea for my first ever Lisp/Scheme program to implement Alan Turing&#8217;s original a-machines from his paper, On Computable Numbers, with an Application to the Entscheidungsproblem (paper available to public). Fun? Oh, I hadn&#8217;t any idea&#8230;

Preamble; choice of implementation
I decided to go with the latest and greatest version [...]]]></description>
			<content:encoded><![CDATA[<p>So, I thought it would be a fun idea for my first ever Lisp/Scheme program to implement Alan Turing&#8217;s original <i>a</i>-machines from his paper, <i><a href="http://plms.oxfordjournals.org/cgi/reprint/s2-42/1/230">On Computable Numbers, with an Application to the Entscheidungsproblem</a></i> (paper available to public). Fun? Oh, I hadn&#8217;t any idea&#8230;</p>
<p><!-- more --></p>
<h3>Preamble; choice of implementation</h3>
<p>I decided to go with the latest and greatest version of Scheme: <a href="http://www.r6rs.org/">R⁶RS</a>. There are currently two implementations available under Ubuntu Linux: <a href="http://ikarus-scheme.org/">Ikarus</a> and <a href="http://www.littlewingpinball.net/mediawiki/index.php/Ypsilon">Ypsilon</a>. I installed both so I wouldn&#8217;t be swayed by any tempting extensions to the standard. <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /> Despite this, I ended up using Ikarus for most testing, as it ran quite a lot faster, although Ypsilon gave <em>much</em> better stack traces.</p>
<p>I also used the <code>streams</code> library for dealing with infinite lists (<a href="http://srfi.schemers.org/srfi-41/srfi-41.html">SRFI 41</a>), which is included with both implementations.</p>
<p><i>Note: I&#8217;ll be providing all the code so that you <em>should</em> be able to copy-paste it into a new file and run it.</i></p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>import <span style="color: #66cc66;">&#40;</span>rnrs<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>rnrs r5rs <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; provides 'delay' &amp; 'force'</span>
    <span style="color: #66cc66;">&#40;</span>streams<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<h3>The Machine</h3>
<p>Turing sought to capture the essence of computation. For this purpose he constructed an idealized machine, which can read and write symbols to an infinitely long piece of tape. We are going to model these idealized machines and see what they can do.</p>
<p>First, we want some types to represent the <i>a</i>-machines (the <i>a</i> is for automatic). Each machine has a set of states (<i>m</i>-configurations) it can be in, each of which contains a mapping from a set of <strong>symbols</strong> to a list of <strong>actions</strong> and a new <strong><i>m</i>-configuration</strong>. I decided that the state would be my basic unit of construction, but twiddled the meaning of <i>m</i>-configuration a tiny bit so that instead of having each configuration contain a mapping from symbols, I would instead have a list of configurations, each one with a list of which symbols activate it. I ended up with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; type for a configuration</span>
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>record<span style="color: #66cc66;">-</span>type m<span style="color: #66cc66;">-</span>cfg
            <span style="color: #66cc66;">&#40;</span>fields symbols operations next<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This defines a new record type called <code>m-cfg</code> with the fields <code>symbols</code>, <code>operations</code> and <code>next</code>. The <code>define-record-type</code> form defines a constructor (<code>make-m-cfg</code>) and accessors for each field (<code>m-cfg-*</code>). Rather than have a &#8216;machine&#8217; type, I decided that this would just be left implicit; if we know what the current state is then we can follow the links to <code>next</code> whenever we want to.</p>
<h3>The Tape</h3>
<p>Now, each machine operates upon an infinitely long &#8216;tape&#8217;. To model this, I use two streams, which are infinite lists. One is the infinite length of the tape to the left of the machine, and the other is the infinite length of the tape to the right of the machine. I decided that the first item in the right list would be the current item that the machine is reading.</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; type for a tape (modeled as two stacks)</span>
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>record<span style="color: #66cc66;">-</span>type tape
            <span style="color: #66cc66;">&#40;</span>fields left right <span style="color: #b1b100;">min</span> <span style="color: #b1b100;">max</span> index<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>You will note that there are also the fields <code>min</code>, <code>max</code>, and <code>index</code>. These are solely used to track how much of the tape the machine has &#8220;visited&#8221;. Without this information, we would not know how much of the tape to show when we want to look at it; and since it is infinitely long, this could be a problem! <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
<h3>Representing operations</h3>
<p>The <code>operations</code> that a machine can perform consist of:</p>
<ul>
<li>Move right</li>
<li>Move left</li>
<li>Print symbol</li>
<li>Erase symbol</li>
<li>Halt</li>
</ul>
<p>I implemented these as an enumeration, just in case, but I didn&#8217;t actually end up utilizing any of the enumeration features.</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; the operations available</span>
<span style="color: #66cc66;">&#40;</span>define<span style="color: #66cc66;">-</span>enumeration op
  <span style="color: #66cc66;">&#40;</span>right left erase print halt<span style="color: #66cc66;">&#41;</span>
  op<span style="color: #66cc66;">-</span>set<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>There is a small difficulty with this representation: the &#8216;print&#8217; operation needs to be able to take an argument. I decided that operations would always be passed around as lists, and that only &#8216;print&#8217; would have a second element in the list: its argument. Here is a little shorthand to make this representation easier:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; these need to be lists, because print takes an argument</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #b1b100;">L</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>op left<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> R <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>op right<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> P <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>op print<span style="color: #66cc66;">&#41;</span> c<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #b1b100;">E</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>op erase<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> H <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>op halt<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Thus, we can represent a list of operations like this: <code>(list R R (P #\A) L E H)</code>—that&#8217;s right, right, print &#8216;A&#8217; (Scheme&#8217;s syntax for characters is a little weird), left, erase, halt.</p>
<h3>Moving around on the tape</h3>
<p>Here is a simple tape; it is completely empty. Note that I use the symbol <code>'empty</code> to represent empty places on the tape. <code>stream-constant</code> makes an infinite stream of the value(s) supplied.</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> empty<span style="color: #66cc66;">-</span>tape
  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>tape <span style="color: #66cc66;">&#40;</span>stream<span style="color: #66cc66;">-</span>constant 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>stream<span style="color: #66cc66;">-</span>constant 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Next we need code to actually implement the operations described above. It is fairly straightforward, but we also have to keep track of the index and max/min points on the tape:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; Tape manipulation:</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>current<span style="color: #66cc66;">-</span>symbol tape<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>stream<span style="color: #66cc66;">-</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>right tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>item from to<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>values <span style="color: #66cc66;">&#40;</span>stream<span style="color: #66cc66;">-</span><span style="color: #b1b100;">cdr</span> from<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>stream<span style="color: #66cc66;">-</span><span style="color: #b1b100;">cons</span> <span style="color: #66cc66;">&#40;</span>stream<span style="color: #66cc66;">-</span><span style="color: #b1b100;">car</span> from<span style="color: #66cc66;">&#41;</span> to<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>right tape<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>let<span style="color: #66cc66;">-</span>values <span style="color: #66cc66;">&#40;</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>right left<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>item <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>right tape<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>left tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">min</span> <span style="color: #b1b100;">max</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>update<span style="color: #66cc66;">-</span>min<span style="color: #66cc66;">-</span><span style="color: #b1b100;">max</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span><span style="color: #b1b100;">min</span> tape<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span><span style="color: #b1b100;">max</span> tape<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>tape left right <span style="color: #b1b100;">min</span> <span style="color: #b1b100;">max</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>left tape<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>let<span style="color: #66cc66;">-</span>values <span style="color: #66cc66;">&#40;</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>left right<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>item <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>left tape<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>right tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">min</span> <span style="color: #b1b100;">max</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>update<span style="color: #66cc66;">-</span>min<span style="color: #66cc66;">-</span><span style="color: #b1b100;">max</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span><span style="color: #b1b100;">min</span> tape<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span><span style="color: #b1b100;">max</span> tape<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index tape<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>tape left right <span style="color: #b1b100;">min</span> <span style="color: #b1b100;">max</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index tape<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>print tape symbol<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>tape
    <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>left tape<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>stream<span style="color: #66cc66;">-</span><span style="color: #b1b100;">cons</span> symbol <span style="color: #66cc66;">&#40;</span>stream<span style="color: #66cc66;">-</span><span style="color: #b1b100;">cdr</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>right tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span><span style="color: #b1b100;">min</span> tape<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span><span style="color: #b1b100;">max</span> tape<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>erase tape<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>print tape 'empty<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>update<span style="color: #66cc66;">-</span>min<span style="color: #66cc66;">-</span><span style="color: #b1b100;">max</span> <span style="color: #b1b100;">min</span> <span style="color: #b1b100;">max</span> i<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> 
    <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&lt;</span> i <span style="color: #b1b100;">min</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>values i <span style="color: #b1b100;">max</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> i <span style="color: #b1b100;">max</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>values <span style="color: #b1b100;">min</span> i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span>      <span style="color: #66cc66;">&#40;</span>values <span style="color: #b1b100;">min</span> <span style="color: #b1b100;">max</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Notice that erase is actually redundant because we can just print <code>'empty</code>. We also want a &#8220;dispatcher&#8221; of sorts that takes a value representing an operation and performs that operation. This is where passing the argument around with the &#8216;print&#8217; came in useful:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; performs an operation on a tape, returns new tape</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>perform<span style="color: #66cc66;">-</span>op tape oper<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">case</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> oper<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>op left<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>left tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>op right<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>right tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>op print<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>print tape <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cadr</span> oper<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>op erase<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>erase tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
    <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>op halt<span style="color: #66cc66;">&#41;</span> #f<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; ungraceful halt!</span></pre></div></div>

<h3>Running the machine</h3>
<p>Now that we have the operations implemented, we can almost run a state against a tape. First we need to figure out just which of the configurations of the state to run. This procedure receives a <strong>list</strong> of configurations (but they are all part of the same ‘state’) and a symbol, and picks the first configuration that has a matching symbol. Note that the configurations can also have the symbol <code>'any</code>, which matches anything.</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; finds the correct rule to follow for this symbol</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>find<span style="color: #66cc66;">-</span>cfg machine symbol<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>find <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>cfg<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">or</span>
                <span style="color: #66cc66;">&#40;</span>find <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">s</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> symbol <span style="color: #b1b100;">s</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
                  <span style="color: #66cc66;">&#40;</span>m<span style="color: #66cc66;">-</span>cfg<span style="color: #66cc66;">-</span>symbols cfg<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>find <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">s</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> 'any <span style="color: #b1b100;">s</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
                  <span style="color: #66cc66;">&#40;</span>m<span style="color: #66cc66;">-</span>cfg<span style="color: #66cc66;">-</span>symbols cfg<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        machine<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Now that we have a way to find out which rule to perform, and how to perform it, we can run it against a tape. This procedure advances the machine to the next state, performing all the operations needed. It returns the new state and a new tape.</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; runs a machine forward one step</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>run<span style="color: #66cc66;">-</span>machine tape machine<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>cfg <span style="color: #66cc66;">&#40;</span>find<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">force</span> machine<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>current<span style="color: #66cc66;">-</span>symbol tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>fold<span style="color: #66cc66;">-</span>left perform<span style="color: #66cc66;">-</span>op tape <span style="color: #66cc66;">&#40;</span>m<span style="color: #66cc66;">-</span>cfg<span style="color: #66cc66;">-</span>operations cfg<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span>m<span style="color: #66cc66;">-</span>cfg<span style="color: #66cc66;">-</span>next cfg<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<h3>Displaying the tape</h3>
<p>Being able to run the machine against a tape isn&#8217;t much good if we can&#8217;t see the result, so here&#8217;s a procedure to print out what it looks like. This is where we need the indexes we kept track of on the tape, so we know when to stop printing.</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>print<span style="color: #66cc66;">-</span>tape tape<span style="color: #66cc66;">&#41;</span>
  <span style="color: #808080; font-style: italic;">; move as far left as possible</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>leftTape <span style="color: #66cc66;">&#40;</span>go<span style="color: #66cc66;">-</span>far<span style="color: #66cc66;">-</span>left tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #808080; font-style: italic;">; now go right</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">do</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">t</span> leftTape<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index <span style="color: #b1b100;">t</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span><span style="color: #b1b100;">max</span> tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">t</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index tape<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index <span style="color: #b1b100;">t</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
              <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">display</span> <span style="color: #ff0000;">&quot;[&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>
          <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> <span style="color: #66cc66;">&#40;</span>current<span style="color: #66cc66;">-</span>symbol <span style="color: #b1b100;">t</span><span style="color: #66cc66;">&#41;</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">display</span> <span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
          <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">display</span> <span style="color: #66cc66;">&#40;</span>current<span style="color: #66cc66;">-</span>symbol <span style="color: #b1b100;">t</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>when <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index tape<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index <span style="color: #b1b100;">t</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
              <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">display</span> <span style="color: #ff0000;">&quot;]&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> <span style="color: #b1b100;">t</span> <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>right <span style="color: #b1b100;">t</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; moves to the far left of the tape (as far as has been travelled)</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>go<span style="color: #66cc66;">-</span>far<span style="color: #66cc66;">-</span>left tape<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">do</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">t</span> tape<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span>index <span style="color: #b1b100;">t</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>tape<span style="color: #66cc66;">-</span><span style="color: #b1b100;">min</span> tape<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">t</span><span style="color: #66cc66;">&#41;</span>
     <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> <span style="color: #b1b100;">t</span> <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>left <span style="color: #b1b100;">t</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>I print out a &#8216;.&#8217; for each blank, and surround the current symbol with square brackets (actually I&#8217;ve changed that to be underlining in this blog post).</p>
<h3>Turing Machines!</h3>
<p>Now we can test it! Here is my definition of Turing&#8217;s first published machine:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; Turing's first published machine!</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> m1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">letrec</span> 
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>b <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
       <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> R<span style="color: #66cc66;">&#41;</span> c<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
   <span style="color: #66cc66;">&#91;</span>c <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
       <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">e</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
   <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">e</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
       <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">f</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
   <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">f</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
       <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
  b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Now you see why we needed to import &#8216;delay&#8217;&#8230; since Scheme is a strictly-evaluated language, we can&#8217;t just <code>letrec</code> each state in terms of the others, so I wrap each one up in <code>delay</code>, then <code>force</code> it in one place; just before we use it in the <code>run-machine</code> procedure.</p>
<p>Other than that it is fairly straightforward, each state has a list of <i>m</i>-configurations, each of which has a list of what symbols it accepts, the actions to take, and the next state to move to. After we letrec, we have the initial state defined as the &#8216;machine&#8217;—in this case, <code>b</code>.</p>
<p>We can run this machine like so:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>go <span style="color: #b1b100;">t</span> m<span style="color: #66cc66;">&#41;</span>
 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">do</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>tm <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">t</span> m<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eqv?</span> tm #f<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> tm<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>print<span style="color: #66cc66;">-</span>tape <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> tm<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">newline</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> tm <span style="color: #66cc66;">&#40;</span>run<span style="color: #66cc66;">-</span>machine <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> tm<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cadr</span> tm<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>go empty<span style="color: #66cc66;">-</span>tape m1<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This gives us the following output:</p>
<pre>
<u>.</u>
0<u>.</u>
0.<u>.</u>
0.1<u>.</u>
0.1.<u>.</u>
0.1.0<u>.</u>
0.1.0.<u>.</u>
0.1.0.1<u>.</u>
0.1.0.1.<u>.</u>
0.1.0.1.0<u>.</u>
...
</pre>
<p>This looks correct: P0, R, R, P1, R, R, etc.</p>
<h3>Machine redux</h3>
<p>The next machine Turing gives is the same as the first one, only in a different form:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; the same machine, only smaller</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> m2 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">letrec</span>
         <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>b <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
           <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> b<span style="color: #66cc66;">&#41;</span>
           <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> b<span style="color: #66cc66;">&#41;</span>
           <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
         b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>It has only one state, but changes depending on what the current symbol is. This produces the same output as the first machine, but in fewer steps:</p>
<pre>
<u>.</u>
<u>0</u>
0.<u>1</u>
0.1.<u>0</u>
0.1.0.<u>1</u>
0.1.0.1.<u>0</u>
0.1.0.1.0.<u>1</u>
0.1.0.1.0.1.<u>0</u>
0.1.0.1.0.1.0.<u>1</u>
0.1.0.1.0.1.0.1.<u>0</u>
...</pre>
<p>You may be wondering why Turing leaves blanks between each printed symbol. He used the convention that only the &#8216;even&#8217; squares (termed <i>F</i>-squares) would be the output. The &#8216;odd&#8217; squares (termed <i>E</i>-squares) would be used as a scratch-pad.</p>
<h3>Machine-à-trois</h3>
<p>The third machine is a little more interesting. Whereas the first two printed out <code>01010101...</code>, this prints <code>01011011101111011111...</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; Turing's third machine</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> m3 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">letrec</span>
         <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>b <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                   <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>P #\ǝ<span style="color: #66cc66;">&#41;</span> R <span style="color: #66cc66;">&#40;</span>P #\ǝ<span style="color: #66cc66;">&#41;</span> R <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> R R <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> o<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
          <span style="color: #66cc66;">&#91;</span>o <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R <span style="color: #66cc66;">&#40;</span>P #\x<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> o<span style="color: #66cc66;">&#41;</span>
                  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> q<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
          <span style="color: #66cc66;">&#91;</span>q <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\<span style="color: #cc66cc;">0</span> #\<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R<span style="color: #66cc66;">&#41;</span> q<span style="color: #66cc66;">&#41;</span>
                  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> p<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
          <span style="color: #66cc66;">&#91;</span>p <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\x<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">E</span> R<span style="color: #66cc66;">&#41;</span> q<span style="color: #66cc66;">&#41;</span>
                  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\ǝ<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">f</span><span style="color: #66cc66;">&#41;</span>
                  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> p<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
          <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">f</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> o<span style="color: #66cc66;">&#41;</span>
                  <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">f</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
         b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>With the output:</p>
<pre>
<u>.</u>
ǝǝ<u>0</u>.0
ǝǝ<u>0</u>.0
ǝǝ0.<u>0</u>
ǝǝ0.0.<u>.</u>
ǝǝ0.0<u>.</u>1
ǝǝ0<u>.</u>0.1
ǝ<u>ǝ</u>0.0.1
ǝǝ<u>0</u>.0.1
ǝǝ0.<u>0</u>.1
ǝǝ0.0.<u>1</u>
ǝǝ0.0.1.<u>.</u>
ǝǝ0.0.<u>1</u>.0
ǝǝ0.<u>0</u>.1x0
ǝǝ0.<u>0</u>.1x0
ǝǝ0.0.<u>1</u>x0
ǝǝ0.0.1x<u>0</u>
ǝǝ0.0.1x0.<u>.</u>
ǝǝ0.0.1x0<u>.</u>1
ǝǝ0.0.1<u>x</u>0.1
ǝǝ0.0.1.<u>0</u>.1
ǝǝ0.0.1.0.<u>1</u>
ǝǝ0.0.1.0.1.<u>.</u>
ǝǝ0.0.1.0.1<u>.</u>1
ǝǝ0.0.1.0<u>.</u>1.1
ǝǝ0.0.1<u>.</u>0.1.1
ǝǝ0.0<u>.</u>1.0.1.1
ǝǝ0<u>.</u>0.1.0.1.1
ǝ<u>ǝ</u>0.0.1.0.1.1
ǝǝ<u>0</u>.0.1.0.1.1
ǝǝ0.<u>0</u>.1.0.1.1
ǝǝ0.0.<u>1</u>.0.1.1
ǝǝ0.0.1.<u>0</u>.1.1
ǝǝ0.0.1.0.<u>1</u>.1
ǝǝ0.0.1.0.1.<u>1</u>
ǝǝ0.0.1.0.1.1.<u>.</u>
ǝǝ0.0.1.0.1.<u>1</u>.0
ǝǝ0.0.1.0.<u>1</u>.1x0
ǝǝ0.0.1.<u>0</u>.1x1x0
ǝǝ0.0.1.<u>0</u>.1x1x0
ǝǝ0.0.1.0.<u>1</u>x1x0
ǝǝ0.0.1.0.1x<u>1</u>x0
ǝǝ0.0.1.0.1x1x<u>0</u>
ǝǝ0.0.1.0.1x1x0.<u>.</u>
ǝǝ0.0.1.0.1x1x0<u>.</u>1
ǝǝ0.0.1.0.1x1<u>x</u>0.1
ǝǝ0.0.1.0.1x1.<u>0</u>.1
ǝǝ0.0.1.0.1x1.0.<u>1</u>
ǝǝ0.0.1.0.1x1.0.1.<u>.</u>
ǝǝ0.0.1.0.1x1.0.1<u>.</u>1
ǝǝ0.0.1.0.1x1.0<u>.</u>1.1
ǝǝ0.0.1.0.1x1<u>.</u>0.1.1
ǝǝ0.0.1.0.1<u>x</u>1.0.1.1
ǝǝ0.0.1.0.1.<u>1</u>.0.1.1
ǝǝ0.0.1.0.1.1.<u>0</u>.1.1
ǝǝ0.0.1.0.1.1.0.<u>1</u>.1
ǝǝ0.0.1.0.1.1.0.1.<u>1</u>
ǝǝ0.0.1.0.1.1.0.1.1.<u>.</u>
ǝǝ0.0.1.0.1.1.0.1.1<u>.</u>1
ǝǝ0.0.1.0.1.1.0.1<u>.</u>1.1
ǝǝ0.0.1.0.1.1.0<u>.</u>1.1.1
ǝǝ0.0.1.0.1.1<u>.</u>0.1.1.1
ǝǝ0.0.1.0.1<u>.</u>1.0.1.1.1
ǝǝ0.0.1.0<u>.</u>1.1.0.1.1.1
ǝǝ0.0.1<u>.</u>0.1.1.0.1.1.1
ǝǝ0.0<u>.</u>1.0.1.1.0.1.1.1
ǝǝ0<u>.</u>0.1.0.1.1.0.1.1.1
ǝ<u>ǝ</u>0.0.1.0.1.1.0.1.1.1
ǝǝ<u>0</u>.0.1.0.1.1.0.1.1.1
ǝǝ0.<u>0</u>.1.0.1.1.0.1.1.1
ǝǝ0.0.<u>1</u>.0.1.1.0.1.1.1
ǝǝ0.0.1.<u>0</u>.1.1.0.1.1.1
ǝǝ0.0.1.0.<u>1</u>.1.0.1.1.1
ǝǝ0.0.1.0.1.<u>1</u>.0.1.1.1
ǝǝ0.0.1.0.1.1.<u>0</u>.1.1.1
ǝǝ0.0.1.0.1.1.0.<u>1</u>.1.1
ǝǝ0.0.1.0.1.1.0.1.<u>1</u>.1
ǝǝ0.0.1.0.1.1.0.1.1.<u>1</u>
ǝǝ0.0.1.0.1.1.0.1.1.1.<u>.</u>
ǝǝ0.0.1.0.1.1.0.1.1.<u>1</u>.0
ǝǝ0.0.1.0.1.1.0.1.<u>1</u>.1x0
ǝǝ0.0.1.0.1.1.0.<u>1</u>.1x1x0
ǝǝ0.0.1.0.1.1.<u>0</u>.1x1x1x0
ǝǝ0.0.1.0.1.1.<u>0</u>.1x1x1x0
ǝǝ0.0.1.0.1.1.0.<u>1</u>x1x1x0
ǝǝ0.0.1.0.1.1.0.1x<u>1</u>x1x0
ǝǝ0.0.1.0.1.1.0.1x1x<u>1</u>x0
ǝǝ0.0.1.0.1.1.0.1x1x1x<u>0</u>
ǝǝ0.0.1.0.1.1.0.1x1x1x0.<u>.</u>
ǝǝ0.0.1.0.1.1.0.1x1x1x0<u>.</u>1
ǝǝ0.0.1.0.1.1.0.1x1x1<u>x</u>0.1
ǝǝ0.0.1.0.1.1.0.1x1x1.<u>0</u>.1
ǝǝ0.0.1.0.1.1.0.1x1x1.0.<u>1</u>
ǝǝ0.0.1.0.1.1.0.1x1x1.0.1.<u>.</u>
ǝǝ0.0.1.0.1.1.0.1x1x1.0.1<u>.</u>1
ǝǝ0.0.1.0.1.1.0.1x1x1.0<u>.</u>1.1
ǝǝ0.0.1.0.1.1.0.1x1x1<u>.</u>0.1.1
ǝǝ0.0.1.0.1.1.0.1x1<u>x</u>1.0.1.1
ǝǝ0.0.1.0.1.1.0.1x1.<u>1</u>.0.1.1
ǝǝ0.0.1.0.1.1.0.1x1.1.<u>0</u>.1.1
ǝǝ0.0.1.0.1.1.0.1x1.1.0.<u>1</u>.1
ǝǝ0.0.1.0.1.1.0.1x1.1.0.1.<u>1</u>
ǝǝ0.0.1.0.1.1.0.1x1.1.0.1.1.<u>.</u>
ǝǝ0.0.1.0.1.1.0.1x1.1.0.1.1<u>.</u>1
ǝǝ0.0.1.0.1.1.0.1x1.1.0.1<u>.</u>1.1
ǝǝ0.0.1.0.1.1.0.1x1.1.0<u>.</u>1.1.1
ǝǝ0.0.1.0.1.1.0.1x1.1<u>.</u>0.1.1.1
ǝǝ0.0.1.0.1.1.0.1x1<u>.</u>1.0.1.1.1
ǝǝ0.0.1.0.1.1.0.1<u>x</u>1.1.0.1.1.1
ǝǝ0.0.1.0.1.1.0.1.<u>1</u>.1.0.1.1.1
ǝǝ0.0.1.0.1.1.0.1.1.<u>1</u>.0.1.1.1
ǝǝ0.0.1.0.1.1.0.1.1.1.<u>0</u>.1.1.1
ǝǝ0.0.1.0.1.1.0.1.1.1.0.<u>1</u>.1.1
ǝǝ0.0.1.0.1.1.0.1.1.1.0.1.<u>1</u>.1
ǝǝ0.0.1.0.1.1.0.1.1.1.0.1.1.<u>1</u>
ǝǝ0.0.1.0.1.1.0.1.1.1.0.1.1.1.<u>.</u>
ǝǝ0.0.1.0.1.1.0.1.1.1.0.1.1.1<u>.</u>1
ǝǝ0.0.1.0.1.1.0.1.1.1.0.1.1<u>.</u>1.1
ǝǝ0.0.1.0.1.1.0.1.1.1.0.1<u>.</u>1.1.1
ǝǝ0.0.1.0.1.1.0.1.1.1.0<u>.</u>1.1.1.1
ǝǝ0.0.1.0.1.1.0.1.1.1<u>.</u>0.1.1.1.1
ǝǝ0.0.1.0.1.1.0.1.1<u>.</u>1.0.1.1.1.1
ǝǝ0.0.1.0.1.1.0.1<u>.</u>1.1.0.1.1.1.1
ǝǝ0.0.1.0.1.1.0<u>.</u>1.1.1.0.1.1.1.1
ǝǝ0.0.1.0.1.1<u>.</u>0.1.1.1.0.1.1.1.1
ǝǝ0.0.1.0.1<u>.</u>1.0.1.1.1.0.1.1.1.1
ǝǝ0.0.1.0<u>.</u>1.1.0.1.1.1.0.1.1.1.1
ǝǝ0.0.1<u>.</u>0.1.1.0.1.1.1.0.1.1.1.1
ǝǝ0.0<u>.</u>1.0.1.1.0.1.1.1.0.1.1.1.1
ǝǝ0<u>.</u>0.1.0.1.1.0.1.1.1.0.1.1.1.1
ǝ<u>ǝ</u>0.0.1.0.1.1.0.1.1.1.0.1.1.1.1
</pre>
<p>Here we can see the scratch-pad being used. We can also see the beginnings of a pattern of execution; notice how the machine returns to the beginning of the tape after completing each set of <code>1</code>s.</p>
<h3>Opus Magnum</h3>
<p>Next up was my main challenge. One of the major contributions of Turing&#8217;s paper was to display a machine which could emulate <em>any other</em> machine you wanted. In essence, you don&#8217;t actually need lots of different machines. You can just build one, and it can do anything any of the other machines can do! This is the principle behind modern general-purpose computers.</p>
<p>This is a very big, and complex machine. Some of the intricacies not involved in the other machines are:</p>
<ul>
<li><i>m</i>-functions; that is, configurations which accept parameters—luckily, this was surprisingly easy to implement using Scheme; I simply wrap the <code>delay</code>ed code inside another lambda</li>
<li><i>m</i>-configurations which are parametrized over all symbols on the machine—this is solved by just <code>map</code>ping a lambda over the list of symbols</li>
<li>variadic <i>m</i>-functions—solved by the magic of <code>case-lambda</code></li>
<li>poorly-scanned journal document containing Fraktur and Greek letters <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_razz.gif" alt="" /></li>
</ul>
<p>But not only was this by far the biggest and most complex machine supplied by Turing, I had read <a href="http://www.turing.org.uk/turing/scrapbook/machine.html">texts</a> mentioning unspecified <em>bugs</em> in the program.</p>
<p>&#8230; and sure enough, I ran into a &#8216;bug&#8217;. There were some configurations used in the machine which <em>weren&#8217;t defined in the paper</em>! At first I thought this was due to the low resolution of the PDF, but even enhancing the image didn&#8217;t help.</p>
<p>After much supplication and burnt offerings to the God of the Internet, I managed to find that:</p>
<h4>Someone else did the work already</h4>
<p>Yay!</p>
<p>More specifically, I found a paper entitled <i><a href="http://comjnl.oxfordjournals.org/cgi/content/abstract/36/4/351">Understanding Turing&#8217;s Universal Machine — Personal Style in Program Description </a></i> (which is unfortunately not available to the public), a marvelous paper that not only explains the errors made in detail, but also provides a nice, corrected version of Turing&#8217;s exposition of his machine.</p>
<p>After painstakingly re-checking all the states again, I arrived at this:</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; need this to generate a couple of cfgs</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> u<span style="color: #66cc66;">-</span>symbols <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
		   #\A #\C #\<span style="color: #b1b100;">D</span> #\<span style="color: #cc66cc;">0</span> #\<span style="color: #cc66cc;">1</span>
		   #\u #\v #\w #\x #\y #\z
		   #\<span style="color: #808080; font-style: italic;">; #\L #\R #\N</span>
		   #\∷ #\:
		   <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">; yo dawg</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> u <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">letrec</span>
        <span style="color: #66cc66;">&#40;</span>
         <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">f</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\ǝ<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>f1 C B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">f</span> C B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>f1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>f2 C B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>f1 C B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>f2 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> B<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>f1 C B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>fdash <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">f</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">l</span> C<span style="color: #66cc66;">&#41;</span> B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>fdashdash <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">f</span> <span style="color: #66cc66;">&#40;</span>r C<span style="color: #66cc66;">&#41;</span> B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>r <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">l</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>q <span style="color: #66cc66;">&#40;</span>case<span style="color: #66cc66;">-</span><span style="color: #b1b100;">lambda</span>
              <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>q1 C<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>q C<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>C a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>q <span style="color: #66cc66;">&#40;</span>q1 C a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>q1 <span style="color: #66cc66;">&#40;</span>case<span style="color: #66cc66;">-</span><span style="color: #b1b100;">lambda</span>
               <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>q C<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
               <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>C a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>q1 C a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>pe <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">f</span> <span style="color: #66cc66;">&#40;</span>pe1 C b<span style="color: #66cc66;">&#41;</span> c #\ǝ<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>pe1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>P b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>pe1 C b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>pe2 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C a b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>pe <span style="color: #66cc66;">&#40;</span>pe C b<span style="color: #66cc66;">&#41;</span> a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>c <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>fdash <span style="color: #66cc66;">&#40;</span>c1 C<span style="color: #66cc66;">&#41;</span> B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>c1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span>
                    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>pe C b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                      u<span style="color: #66cc66;">-</span>symbols<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>ce <span style="color: #66cc66;">&#40;</span>case<span style="color: #66cc66;">-</span><span style="color: #b1b100;">lambda</span>
               <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>C B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>c <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> C B a<span style="color: #66cc66;">&#41;</span> B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
               <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>ce <span style="color: #66cc66;">&#40;</span>ce B a<span style="color: #66cc66;">&#41;</span> B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>ce2 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>B a b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>ce <span style="color: #66cc66;">&#40;</span>ce B b<span style="color: #66cc66;">&#41;</span> a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>ce3 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>B a b g<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>ce <span style="color: #66cc66;">&#40;</span>ce2 B b g<span style="color: #66cc66;">&#41;</span> a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>ce5 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>B a b g <span style="color: #b1b100;">d</span> <span style="color: #b1b100;">e</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>ce3 <span style="color: #66cc66;">&#40;</span>ce2 B <span style="color: #b1b100;">d</span> <span style="color: #b1b100;">e</span><span style="color: #66cc66;">&#41;</span> a b g<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #808080; font-style: italic;">; added</span>
         <span style="color: #66cc66;">&#91;</span>cp <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C U <span style="color: #b1b100;">F</span> a b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>fdash <span style="color: #66cc66;">&#40;</span>cp1 C U b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">f</span> U <span style="color: #b1b100;">F</span> b<span style="color: #66cc66;">&#41;</span> a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>cp1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C U b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span>
                   <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>g<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> g<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>fdash <span style="color: #66cc66;">&#40;</span>cp2 C U g<span style="color: #66cc66;">&#41;</span> U b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                     u<span style="color: #66cc66;">-</span>symbols<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>cp2 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C U g<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> g<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> U<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>cpe <span style="color: #66cc66;">&#40;</span>case<span style="color: #66cc66;">-</span><span style="color: #b1b100;">lambda</span> 
                <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>C U <span style="color: #b1b100;">F</span> a b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                 <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>cp <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> C C b<span style="color: #66cc66;">&#41;</span> C a<span style="color: #66cc66;">&#41;</span> U <span style="color: #b1b100;">F</span> a b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
                <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>U <span style="color: #b1b100;">F</span> a b<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                 <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>cpe <span style="color: #66cc66;">&#40;</span>cpe U <span style="color: #b1b100;">F</span> a b<span style="color: #66cc66;">&#41;</span> U <span style="color: #b1b100;">F</span> a b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">e</span> <span style="color: #66cc66;">&#40;</span>case<span style="color: #66cc66;">-</span><span style="color: #b1b100;">lambda</span>
               <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\ǝ<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>e1 C<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> C<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
               <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> B a<span style="color: #66cc66;">&#41;</span> B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
               <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>C B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">f</span> <span style="color: #66cc66;">&#40;</span>e1 C B a<span style="color: #66cc66;">&#41;</span> B a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>e1 <span style="color: #66cc66;">&#40;</span>case<span style="color: #66cc66;">-</span><span style="color: #b1b100;">lambda</span>
               <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span> 
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R <span style="color: #b1b100;">E</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>e1 C<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
               <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>C B a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">E</span><span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>con <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\A<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span> <span style="color: #66cc66;">&#40;</span>P a<span style="color: #66cc66;">&#41;</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>con1 C a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>con C a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>con1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\A<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R <span style="color: #66cc66;">&#40;</span>P a<span style="color: #66cc66;">&#41;</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>con1 C a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\<span style="color: #b1b100;">D</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R <span style="color: #66cc66;">&#40;</span>P a<span style="color: #66cc66;">&#41;</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>con2 C a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>con2 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>C a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R <span style="color: #66cc66;">&#40;</span>P a<span style="color: #66cc66;">&#41;</span> R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>con2 C a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R<span style="color: #66cc66;">&#41;</span> C<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>b <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">f</span> b1 b1 #\∷<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>b1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R <span style="color: #66cc66;">&#40;</span>P #\:<span style="color: #66cc66;">&#41;</span> R R <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #b1b100;">D</span><span style="color: #66cc66;">&#41;</span> R R <span style="color: #66cc66;">&#40;</span>P #\A<span style="color: #66cc66;">&#41;</span> R R <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #b1b100;">D</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> anf<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #808080; font-style: italic;">; added &quot;R R PD&quot;</span>
         <span style="color: #66cc66;">&#91;</span>anf <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>q anf1 #\:<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #808080; font-style: italic;">; corrected from &quot;(g ...&quot;</span>
         <span style="color: #66cc66;">&#91;</span>anf1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>con fom #\y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>fom <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\<span style="color: #808080; font-style: italic;">;) (list R (P #\z) L) (con fmp #\x))</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\z<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> fom<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\ǝ<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> H<span style="color: #66cc66;">&#41;</span> fom<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> fom<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>fmp <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>cpe <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> anf #\x<span style="color: #66cc66;">&#41;</span> #\y<span style="color: #66cc66;">&#41;</span> sim #\x #\y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #808080; font-style: italic;">; corrected</span>
         <span style="color: #66cc66;">&#91;</span>sim <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>fdash sim1 sim1 #\z<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>sim1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>con sim2 'empty<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>sim2 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\A<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> sim3<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span> <span style="color: #66cc66;">&#40;</span>P #\u<span style="color: #66cc66;">&#41;</span> R R R<span style="color: #66cc66;">&#41;</span> sim2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #808080; font-style: italic;">; corrected from &quot;R ...&quot;</span>
         <span style="color: #66cc66;">&#91;</span>sim3 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\A<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span> <span style="color: #66cc66;">&#40;</span>P #\y<span style="color: #66cc66;">&#41;</span> R R R<span style="color: #66cc66;">&#41;</span> sim3<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span> <span style="color: #66cc66;">&#40;</span>P #\y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> mf #\z<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>mf <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>q mf1 #\:<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #808080; font-style: italic;">; corrected from &quot;(g mf ...&quot;</span>
         <span style="color: #66cc66;">&#91;</span>mf1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\A<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> mf2<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R<span style="color: #66cc66;">&#41;</span> mf1<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>mf2 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R <span style="color: #66cc66;">&#40;</span>P #\x<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> mf2<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\:<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> mf4<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\<span style="color: #b1b100;">D</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R <span style="color: #66cc66;">&#40;</span>P #\x<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> mf3<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>mf3 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\:<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> mf4<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R <span style="color: #66cc66;">&#40;</span>P #\v<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> mf3<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>mf4 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>con <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">l</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">l</span> mf5<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 'empty<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>mf5 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>P #\:<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> sh<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R <span style="color: #66cc66;">&#40;</span>P #\w<span style="color: #66cc66;">&#41;</span> R<span style="color: #66cc66;">&#41;</span> mf5<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>sh <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">f</span> sh1 inst #\u<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>sh1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span> <span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> sh2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>sh2 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\<span style="color: #b1b100;">D</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R R R<span style="color: #66cc66;">&#41;</span> sh3<span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; corrected from &quot;sh2&quot;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> inst<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>sh3 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R<span style="color: #66cc66;">&#41;</span> sh4<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> inst<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>sh4 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R R<span style="color: #66cc66;">&#41;</span> sh5<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>pe2 inst #\<span style="color: #cc66cc;">0</span> #\:<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>sh5 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\C<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> inst<span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>pe2 inst #\<span style="color: #cc66cc;">1</span> #\:<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>inst <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>                                 <span style="color: #808080; font-style: italic;">; note that inst1 is forced here!</span>
                                                            <span style="color: #808080; font-style: italic;">; this is because it is a zero-arity varargs</span>
                <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>q <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">l</span> <span style="color: #66cc66;">&#40;</span>inst1<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> #\u<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #808080; font-style: italic;">; corrected from &quot;(g ...&quot; </span>
         <span style="color: #66cc66;">&#91;</span>inst1 <span style="color: #66cc66;">&#40;</span>case<span style="color: #66cc66;">-</span><span style="color: #b1b100;">lambda</span>
                 <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span>
                       <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> a<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> R <span style="color: #b1b100;">E</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>inst1 a<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                       u<span style="color: #66cc66;">-</span>symbols<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
                 <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">case</span> x
                      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>#\<span style="color: #b1b100;">L</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>ce5 ov #\v #\y #\x #\u #\w<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
                      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>#\R<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>ce5 ov #\v #\x #\u #\y #\w<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
                      <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#40;</span>#\N<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>ce5 ov #\v #\x #\y #\u #\w<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#91;</span>ov <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
               <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'any<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>q <span style="color: #66cc66;">&#40;</span>r <span style="color: #66cc66;">&#40;</span>r ov1<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> #\A<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #808080; font-style: italic;">; changed from original</span>
         <span style="color: #66cc66;">&#91;</span>ov1 <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">delay</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span>
               <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\<span style="color: #b1b100;">D</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> anf<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
               <span style="color: #66cc66;">&#40;</span>make<span style="color: #66cc66;">-</span>m<span style="color: #66cc66;">-</span>cfg <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 'empty<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>P #\<span style="color: #b1b100;">D</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">e</span> anf<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
         <span style="color: #66cc66;">&#41;</span> b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">;; start in state 'b'</span></pre></div></div>

<p>I don&#8217;t think I can blame Turing much for the errors in the paper. It seems as though some arose through printing typos, and attempting to debug this baroque machine by hand, on paper, would have been a difficult task. (I don&#8217;t think he even had Visual Studio!)</p>
<h3>A machine in a machine</h3>
<p>Of course, the final test of this is to see whether this machine can actually emulate another like it is supposed to. I defined a short procedure to set up a machine on a tape according to Turing&#8217;s ingenious encoding.</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>setup<span style="color: #66cc66;">-</span>tape tape inits<span style="color: #66cc66;">&#41;</span> 
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">t</span> <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>right <span style="color: #66cc66;">&#40;</span>print <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>right <span style="color: #66cc66;">&#40;</span>print tape #\ǝ<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> #\ǝ<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
  	<span style="color: #66cc66;">&#91;</span>inits <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">append</span> inits <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> #\∷<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#40;</span>go<span style="color: #66cc66;">-</span>far<span style="color: #66cc66;">-</span>left <span style="color: #66cc66;">&#40;</span>fold<span style="color: #66cc66;">-</span>left <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span>tape init<span style="color: #66cc66;">&#41;</span>
  	       <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>right <span style="color: #66cc66;">&#40;</span>move<span style="color: #66cc66;">-</span>right <span style="color: #66cc66;">&#40;</span>print tape init<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> 
	     <span style="color: #b1b100;">t</span> inits<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<h4>A quick explanation of Turing&#8217;s encoding</h4>
<p>The idea is to first simplify, then encode the states. Turing noted that many of the <i>m</i>-configurations&#8217; operations could be considered redundant:</p>
<ul>
<li>as mentioned above, instead of having &#8220;erase&#8221; we can simply print the &#8216;blank&#8217; symbol</li>
<li>instead of <em>not</em> modifying the symbol, we simply print the symbol already present</li>
</ul>
<p>There are then only three types of operation each state needs to perform:</p>
<ol>
<li>print something and go left</li>
<li>print something and go right</li>
<li>print something and stay put</li>
</ol>
<p>States which have a sequence of operations can be split into a series of states, each of which transfers control to the next one.</p>
<p>Now, if we encode all the symbols and configurations as numbers, we can write them out. Turing chose to encode them via this scheme:</p>
<ul>
<li>configurations&#8217; numbers are the symbol &#8216;D&#8217; followed by <i>n</i> &#8216;A&#8217;s, where <i>n</i> is the number of the state</li>
<li>symbols&#8217; numbers are similar, with &#8216;D&#8217; followed by <i>n</i> &#8216;C&#8217;s. (Turing set &#8216;blank&#8217; to always be symbol 0, represented as simply “D”)</li>
</ul>
<p>So to encode each configuration, we write down its number, the symbol it accepts, the symbol it outputs, which direction to move, and which state to go to next. We prefix each configuration with &#8216;;&#8217;. (When we input it into the machine we also sandwich the whole thing between &#8216;ǝǝ&#8217; and &#8216;∷&#8217;.)</p>
<p>Here is the example which Turing gives in his paper. I have formatted it to make it easier to read. Can you tell what it does?</p>

<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> example <span style="color: #66cc66;">&#40;</span>setup<span style="color: #66cc66;">-</span>tape empty<span style="color: #66cc66;">-</span>tape <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> 
			     #\<span style="color: #808080; font-style: italic;">; #\D #\A             #\D #\D #\C     #\R #\D #\A #\A</span>
			     #\<span style="color: #808080; font-style: italic;">; #\D #\A #\A         #\D #\D         #\R #\D #\A #\A #\A</span>
			     #\<span style="color: #808080; font-style: italic;">; #\D #\A #\A #\A     #\D #\D #\C #\C #\R #\D #\A #\A #\A #\A</span>
			     #\<span style="color: #808080; font-style: italic;">; #\D #\A #\A #\A #\A #\D #\D         #\R #\D #\A)))</span></pre></div></div>

<p><br/><br />
<br/><br />
<br/></p>
<p>If we translate the symbols to get numbers we have the following:</p>
<pre>
; 1 0 0 R 2
; 2 0 . R 3
; 3 0 1 R 4
; 4 0 . R 1
</pre>
<p>This machine prints alternately <code>0.1.0.1.</code>. In fact, when I first typed it up, I left off an &#8216;A&#8217; on the 3rd state and couldn&#8217;t figure out why the machine was printing <code>0.11111...</code>!</p>
<h3>Just to show it works</h3>
<p>Here is some output of the universal machine running the &#8216;0101&#8242; machine. I have only included a snippet as the machine takes a while to get to this stage. You&#8217;ll also notice the output format is different from the other machines; this one outputs some state information and the output of the emulated machine (in this case, 0 and 1), separated by colons. So far, after a minute or so, the machine has output <code>010</code> <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_biggrin.gif" alt="" /></p>
<pre style="overflow:auto">
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D<u>.</u>A.∷.:.D.A.D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.<u>A</u>.∷.:.D.A.D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A<u>.</u>∷.:.D.A.D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.<u>∷</u>.:.D.A.D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷<u>.</u>:.D.A.D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.<u>:</u>.D.A.D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:<u>.</u>D.A.D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.<u>D</u>.A.D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D<u>.</u>A.D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.<u>A</u>.D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A<u>.</u>D.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A.<u>D</u>.:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A.D<u>.</u>:.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A.D.<u>:</u>.0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A.D.:<u>.</u>0.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A.D.:.<u>0</u>.:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A.D.:.0<u>.</u>:.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A.D.:.0.<u>:</u>.D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A.D.:.0.:<u>.</u>D.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A.D.:.0.:.<u>D</u>.C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
.ǝǝ;.D.A.D.DuCuR.DyAyAy;.D.A.A.D.D.R.D.A.A.A.;.D.A.A.A.D.D.C.C.R.D.A.A.A.A.;.D.A.A.A.A.D.D.R.D.A.∷.:.D.A.D.:.0.:.D<u>.</u>C.D.A.A.D.:.D.C.D.D.A.A.A.D.:.1.:.D.C.D.D.C.C.D.A.A.A.A.D.:.D.CvDvDvCvCvDxD.A.D.:.0.:.D.C
</pre>
<p>And that&#8217;s enough for today! Feel free to post corrections, additions, your own Turing machines, and so on <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/debugging-turing-an-excursion-with-scheme/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sometimes it&#8217;s all too much&#8230;</title>
		<link>http://porg.es/blog/sometimes-its-all-too-much</link>
		<comments>http://porg.es/blog/sometimes-its-all-too-much#comments</comments>
		<pubDate>Mon, 22 Jun 2009 13:19:54 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[annoyances]]></category>
		<category><![CDATA[builtins]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[floating-point]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[processor]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=365</guid>
		<description><![CDATA[Argh 

#include &#60;stdio.h&#62;
#include &#60;math.h&#62;
#include &#60;fenv.h&#62;
&#160;
int main &#40;&#41; &#123;
	// don't set rounding here
	double ten0 = sin&#40;pow&#40;10.0,22&#41;&#41;;
&#160;
	fesetround&#40;FE_DOWNWARD&#41;;
	double ten1 = sin&#40;pow&#40;10.0,22&#41;&#41;;
&#160;
	fesetround&#40;FE_UPWARD&#41;;
	double ten2 = sin&#40;pow&#40;10.0,22&#41;&#41;;
&#160;
	fesetround&#40;FE_TONEAREST&#41;;
	double ten3 = sin&#40;pow&#40;10.0,22&#41;&#41;;
&#160;
	fesetround&#40;FE_TOWARDZERO&#41;;
	double ten4 = sin&#40;pow&#40;10.0,22&#41;&#41;;
&#160;
	printf&#40;
		&#34;Default:    %f\n&#34;
		&#34;Downward:   %f\n&#34;
		&#34;Upward:     %f\n&#34;
		&#34;ToNearest:  %f\n&#34;
		&#34;TowardZero: %f\n&#34;,
		ten0, ten1,
		ten2, ten3, ten4&#41;;
&#160;
	return 0;
&#125;


$ gcc test.c -lm -fno-builtin &#38;&#38; ./a.out
Default:    [...]]]></description>
			<content:encoded><![CDATA[<p>Argh <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_sad.gif" alt="" /></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;math.h&gt;</span>
<span style="color: #339933;">#include &lt;fenv.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> main <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// don't set rounding here</span>
	<span style="color: #993333;">double</span> ten0 <span style="color: #339933;">=</span> sin<span style="color: #009900;">&#40;</span>pow<span style="color: #009900;">&#40;</span><span style="color:#800080;">10.0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">22</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	fesetround<span style="color: #009900;">&#40;</span>FE_DOWNWARD<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">double</span> ten1 <span style="color: #339933;">=</span> sin<span style="color: #009900;">&#40;</span>pow<span style="color: #009900;">&#40;</span><span style="color:#800080;">10.0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">22</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	fesetround<span style="color: #009900;">&#40;</span>FE_UPWARD<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">double</span> ten2 <span style="color: #339933;">=</span> sin<span style="color: #009900;">&#40;</span>pow<span style="color: #009900;">&#40;</span><span style="color:#800080;">10.0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">22</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	fesetround<span style="color: #009900;">&#40;</span>FE_TONEAREST<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">double</span> ten3 <span style="color: #339933;">=</span> sin<span style="color: #009900;">&#40;</span>pow<span style="color: #009900;">&#40;</span><span style="color:#800080;">10.0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">22</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	fesetround<span style="color: #009900;">&#40;</span>FE_TOWARDZERO<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">double</span> ten4 <span style="color: #339933;">=</span> sin<span style="color: #009900;">&#40;</span>pow<span style="color: #009900;">&#40;</span><span style="color:#800080;">10.0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">22</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span>
		<span style="color: #ff0000;">&quot;Default:    %f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #ff0000;">&quot;Downward:   %f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #ff0000;">&quot;Upward:     %f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #ff0000;">&quot;ToNearest:  %f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #ff0000;">&quot;TowardZero: %f<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
		ten0<span style="color: #339933;">,</span> ten1<span style="color: #339933;">,</span>
		ten2<span style="color: #339933;">,</span> ten3<span style="color: #339933;">,</span> ten4<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> test.c <span style="color: #660033;">-lm</span> <span style="color: #660033;">-fno-builtin</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> .<span style="color: #000000; font-weight: bold;">/</span>a.out
Default:    <span style="color: #000000;">0.462613</span>
Downward:   <span style="color: #000000;">0.986580</span>
Upward:     <span style="color: #000000;">0.462613</span>
ToNearest:  <span style="color: #000000;">0.462613</span>
TowardZero: <span style="color: #000000;">0.986580</span>
~$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> test.c <span style="color: #660033;">-lm</span>  <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> .<span style="color: #000000; font-weight: bold;">/</span>a.out
Default:    -<span style="color: #000000;">0.852201</span>
Downward:   -<span style="color: #000000;">0.852201</span>
Upward:     -<span style="color: #000000;">0.852201</span>
ToNearest:  -<span style="color: #000000;">0.852201</span>
TowardZero: -<span style="color: #000000;">0.852201</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/sometimes-its-all-too-much/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symbols used to represent functions</title>
		<link>http://porg.es/blog/symbols-used-to-represent-functions</link>
		<comments>http://porg.es/blog/symbols-used-to-represent-functions#comments</comments>
		<pubDate>Mon, 22 Jun 2009 03:51:22 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[utility]]></category>
		<category><![CDATA[9995]]></category>
		<category><![CDATA[iec]]></category>
		<category><![CDATA[iso]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[symbols]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=356</guid>
		<description><![CDATA[I was looking for some standard symbols to represent the Control key and the Alt key, and couldn&#8217;t find one until I came across ISO/IEC 9995-7. 
Because I had much trouble finding a free copy of the document on the ’Net, I have made a table of the symbols and their functions below. I have [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for some standard symbols to represent the Control key and the Alt key, and couldn&#8217;t find one until I came across ISO/IEC 9995-7. <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
<p>Because I had much trouble finding a free copy of the document on the ’Net, I have made a table of the symbols and their functions below. I have marked those not present in Unicode as �.</p>
<p>Some examples: copy is usually [⎈ + C] and close is usually [⎇ + F4].</p>
<table>
<thead>
<tr>
<th style="text-align:right;padding:3px">Symbol</th>
<th>Meaning/Summary</th>
</tr>
</thead>
<tbody>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇧</td>
<td>Select level 2 (AKA Shift)</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇫</td>
<td>Lock level 2 (AKA Shift-Lock)</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇬</td>
<td>Caps lock</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇭</td>
<td>Num lock</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇮</td>
<td>Select level 3</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇯</td>
<td>Lock level 3</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇨</td>
<td>Group select</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇰</td>
<td>Group lock</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">␣</td>
<td>Space</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⍽</td>
<td>No-break space</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎀</td>
<td>Insert</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎁</td>
<td>Underline (continuous)</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎂</td>
<td>Underline (discontinuous)</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎃</td>
<td>Emphasize</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎄</td>
<td>Compose characters</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎅</td>
<td>Center</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⌫</td>
<td>Delete backwards</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">␥</td>
<td>Delete</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎚</td>
<td>Clear screen</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇳</td>
<td>Scrolling (I assume this means Scroll lock)</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Help</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎙</td>
<td>Print Screen</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⏎</td>
<td>Return</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎆</td>
<td>Enter</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎇</td>
<td>Alternate (Alt key)</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎈</td>
<td>Control (Ctrl key)</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎉</td>
<td>Pause</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎊</td>
<td>Break/Interrupt</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎋</td>
<td>Escape</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎌</td>
<td>Undo</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">↑</td>
<td>Cursor up</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">↓</td>
<td>Cursor down</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">←</td>
<td>Cursor left</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">→</td>
<td>Cursor right</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">↟</td>
<td>Fast cursor up</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">↡</td>
<td>Fast cursor down</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">↞</td>
<td>Fast cursor left</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">↠</td>
<td>Fast cursor right</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇱</td>
<td>Home (Beginning)</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇲</td>
<td>End</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎗</td>
<td>Previous page</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎘</td>
<td>Next page</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇤</td>
<td>Tab left</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⇥</td>
<td>Tab right</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Line up</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Line down</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Backspace</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Partial line up</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Partial line down</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Partial space left</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Partial space right</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Set margin left</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Set margin right</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Release margin left</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Release margin right</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">�</td>
<td>Release both margins</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">+</td>
<td>Addition</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">−</td>
<td>Subtraction</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">×</td>
<td>Multiplication</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">÷</td>
<td>Division</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">=</td>
<td>Equals</td>
</tr>
<tr>
<td style="font-size:2em;text-align:right;padding:3px">⎖</td>
<td>Decimal separator</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/symbols-used-to-represent-functions/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pearls Before Piglets</title>
		<link>http://porg.es/blog/pearls-before-piglets</link>
		<comments>http://porg.es/blog/pearls-before-piglets#comments</comments>
		<pubDate>Wed, 27 May 2009 10:40:31 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[Odd]]></category>
		<category><![CDATA[short]]></category>
		<category><![CDATA[silly]]></category>
		<category><![CDATA[umberto eco]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=346</guid>
		<description><![CDATA[While Googling my way through the interwebs, I came across the 2008 Western Australian Certificate of Education sample examination for Stage 2 Biological Sciences. It contains this diagram:

If you&#8217;re wondering, the entire hierarchy is drawn from Umberto Eco&#8217;s novel Baudolino. 
]]></description>
			<content:encoded><![CDATA[<p>While Googling my way through the interwebs, I came across the <a href="http://www.curriculum.wa.edu.au/internet/_Documents/Course_Exams/APRIL+2008+WEB+VERSION+ONLY+Biological+Sciences+Stage+2+Sample+exam+pdf.pdf">2008 Western Australian Certificate of Education sample examination for Stage 2 Biological Sciences</a>. It contains this diagram:</p>
<p><img src="http://porg.es/blog/wp-content/uploads/2009/05/image-0.png" alt="Diagram" title="Diagram" width="454" height="300" class="aligncenter size-full wp-image-347" /></p>
<p>If you&#8217;re wondering, the entire hierarchy is drawn from <a href="http://en.wikipedia.org/wiki/Umberto_Eco">Umberto Eco</a>&#8217;s novel <i><a href="http://en.wikipedia.org/wiki/Baudolino">Baudolino</a></i>. <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/pearls-before-piglets/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What can we fit in 140 characters?</title>
		<link>http://porg.es/blog/what-can-we-fit-in-140-characters</link>
		<comments>http://porg.es/blog/what-can-we-fit-in-140-characters#comments</comments>
		<pubDate>Wed, 27 May 2009 07:09:25 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[silly]]></category>
		<category><![CDATA[stackoverflow]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=327</guid>
		<description><![CDATA[This is in reference to the current ‘Twitter image encoding challenge’ running on StackOverflow.
If we want to restrict ourselves to assigned, non-control, non-private Unicode characters, then by my reckoning that gives us 129,775 available characters.

wget http://unicode.org/Public/UNIDATA/UnicodeData.txt
awk -F ';' UnicodeData.txt -f countUnichars.awk &#124; bc

countUnichars.awk source:

BEGIN { print &#34;ibase=16&#34; } # set bc to hex mode
&#160;
$2 ~ [...]]]></description>
			<content:encoded><![CDATA[<p>This is in reference to the current <a href="http://stackoverflow.com/questions/891643/twitter-image-encoding-challenge">‘Twitter image encoding challenge’ running on StackOverflow</a>.</p>
<p>If we want to restrict ourselves to assigned, non-control, non-private Unicode characters, then by my reckoning that gives us 129,775 available characters.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>unicode.org<span style="color: #000000; font-weight: bold;">/</span>Public<span style="color: #000000; font-weight: bold;">/</span>UNIDATA<span style="color: #000000; font-weight: bold;">/</span>UnicodeData.txt
<span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">';'</span> UnicodeData.txt <span style="color: #660033;">-f</span> countUnichars.awk <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span></pre></div></div>

<p><tt>countUnichars.awk</tt> source:</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">BEGIN { print &quot;ibase=16&quot; } # set bc to hex mode
&nbsp;
$2 ~ /Private/ { # skip any lines with &quot;private&quot; in the description
    getline;
}
&nbsp;
n { # if n is set, then print the range for bc to calculate
    printf(&quot;(%s-%s+1)+&quot;,$1,n);
    n=&quot;&quot;;
}
&nbsp;
$2 ~ /First&gt;/ { # set n if the start of a range
    n=$1;
    getline;
}
&nbsp;
$3 !~ &quot;C.&quot; { # otherwise count anything that isn't some kind of a control character
    i++;
}
&nbsp;
END { # print out the count of everything else
    printf(&quot;%X\n&quot;,i)
}</pre></div></div>

<p>This means we can store exactly 2377 bits (297 bytes) per message (this is <img src='/blog/wp-content/plugins/latexrender/pictures/3d148faa2b961edebbfea91810c1ab28.gif' title='\lfloor\log_2(129775) \times 140\rfloor' alt='\lfloor\log_2(129775) \times 140\rfloor' align=absmiddle>), so if we use a 16-colour palette we can store about 594 pixels (<img src='/blog/wp-content/plugins/latexrender/pictures/cba7624bee8dfdd5dae1931dda7f495d.gif' title='2377/\log_2(16)' alt='2377/\log_2(16)' align=absmiddle>), which can <em>almost</em> reproduce the <i>Mona Lisa</i> thumbnail in the contest page.</p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/what-can-we-fit-in-140-characters/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rhythmbox Plugin: Stop after current track</title>
		<link>http://porg.es/blog/rhythmbox-plugin-stop-after-current-track</link>
		<comments>http://porg.es/blog/rhythmbox-plugin-stop-after-current-track#comments</comments>
		<pubDate>Tue, 07 Apr 2009 05:18:24 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rhythmbox]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=324</guid>
		<description><![CDATA[I have wanted this for a while, and my brother linking me to this post was the last straw.
So here is a very quick and simple plugin; it simply puts a button on the toolbar that you can click when you want to stop playback after the current song. I based the toolbar button code [...]]]></description>
			<content:encoded><![CDATA[<p>I have wanted this for a while, and my brother linking me to <a href="http://unadorned.org/dandruff/archives/2004/02/24/002324.html">this post</a> was the last straw.</p>
<p>So here is a very quick and simple plugin; it simply puts a button on the toolbar that you can click when you want to stop playback after the current song. I based the toolbar button code on <a href="http://code.google.com/p/airmindprojects/">Alexandre Rosenfeld’s lastfm-queue plugin</a>, since I had no idea where to start with that <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
<p>Download it <a href='http://porg.es/blog/wp-content/uploads/2009/04/stop_after_song.zip'>here</a>, and put it into <code>~/.gnome2/rhythmbox/plugins/stop_after_song/</code>. Activate it in Rhythmbox’s plugin dialog.</p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/rhythmbox-plugin-stop-after-current-track/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Email address validation: Simpler, Faster, More Correct</title>
		<link>http://porg.es/blog/email-address-validation-simpler-faster-more-correct</link>
		<comments>http://porg.es/blog/email-address-validation-simpler-faster-more-correct#comments</comments>
		<pubDate>Wed, 11 Mar 2009 11:10:31 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[address]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[rfc]]></category>
		<category><![CDATA[rfc5322]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=317</guid>
		<description><![CDATA[So, I have merged the obsolete-syntax into the code from the last post. This has resulted in shorter, cleaner, faster validation which is also more correct.
I didn’t like the fact that in the old code there were places where explicit try points needed to be included. It seems that these arose because the ‘obsolete’ syntax [...]]]></description>
			<content:encoded><![CDATA[<p>So, I have merged the obsolete-syntax into the code from the last post. This has resulted in shorter, cleaner, faster validation which is <em>also</em> more correct.</p>
<p>I didn’t like the fact that in the old code there were places where explicit <code>try</code> points needed to be included. It seems that these arose because the ‘obsolete’ syntax was tacked-on to the EBNF for the normal syntax, creating much overlap. Since I merged the syntaxes together, there are <em>no</em> explicit try points needed (there are some implicit ones, I believe, such as in <code>optional</code>). This makes the code both faster and easier to understand.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Text<span style="color: #339933; font-weight: bold;">.</span>Email<span style="color: #339933; font-weight: bold;">.</span>Validation <span style="color: green;">&#40;</span>isValid<span style="color: green;">&#41;</span>
<span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>Parsec
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>Parsec<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Char</span>
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Char</span> <span style="color: green;">&#40;</span>chr<span style="color: green;">&#41;</span>
&nbsp;
isValid <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Bool</span>
isValid x <span style="color: #339933; font-weight: bold;">=</span> 	<span style="font-weight: bold;">either</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">const</span> False<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">const</span> True<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>valid x<span style="color: green;">&#41;</span>
&nbsp;
simply <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
<span style="color: #5d478b; font-style: italic;">-- simply converts a parser returning something to a parser returning nothing</span>
&nbsp;
valid <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">String</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Either</span> ParseError <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
valid <span style="color: #339933; font-weight: bold;">=</span> parse addrSpec <span style="background-color: #3cb371;">&quot;&quot;</span>
&nbsp;
addrSpec <span style="color: #339933; font-weight: bold;">=</span> localPart <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> char '<span style="color: #339933; font-weight: bold;">@</span>' <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> domain <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> eof
&nbsp;
localPart <span style="color: #339933; font-weight: bold;">=</span> dottedAtoms
domain <span style="color: #339933; font-weight: bold;">=</span> dottedAtoms <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> domainLiteral 
&nbsp;
dottedAtoms <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">$</span> <span style="color: green;">&#40;</span>optional cfws <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="color: green;">&#40;</span>atom <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> quotedString<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> optional cfws<span style="color: green;">&#41;</span>
	`sepBy1` <span style="color: green;">&#40;</span>char '<span style="color: #339933; font-weight: bold;">.</span>'<span style="color: green;">&#41;</span>
atom <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">$</span> many1 atomText
atomText <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">$</span> alphaNum <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> oneOf <span style="background-color: #3cb371;">&quot;!#$%&amp;'*+-/=?^_`{|}~&quot;</span>
&nbsp;
domainLiteral <span style="color: #339933; font-weight: bold;">=</span>  between <span style="color: green;">&#40;</span>optional cfws <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> char '<span style="color: green;">&#91;</span>'<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>char '<span style="color: green;">&#93;</span>' <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> optional cfws<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span>
	many <span style="color: green;">&#40;</span>optional fws <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> domainText<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> optional fws
domainText <span style="color: #339933; font-weight: bold;">=</span> ranges <span style="color: green;">&#91;</span><span style="color: green;">&#91;</span>33<span style="color: #339933; font-weight: bold;">..</span>90<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span>94<span style="color: #339933; font-weight: bold;">..</span>126<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> obsNoWsCtl
&nbsp;
quotedString <span style="color: #339933; font-weight: bold;">=</span> between <span style="color: green;">&#40;</span>char '<span style="background-color: #3cb371;">&quot;') (char '&quot;</span>'<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span>
	many <span style="color: green;">&#40;</span>optional fws <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> quotedContent<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> optional fws
quotedContent <span style="color: #339933; font-weight: bold;">=</span> quotedText <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> quotedPair
quotedText <span style="color: #339933; font-weight: bold;">=</span> ranges <span style="color: green;">&#91;</span><span style="color: green;">&#91;</span><span style="color: red;">33</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span>35<span style="color: #339933; font-weight: bold;">..</span>91<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span>93<span style="color: #339933; font-weight: bold;">..</span>126<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> obsNoWsCtl
quotedPair <span style="color: #339933; font-weight: bold;">=</span> char '\\' <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="color: green;">&#40;</span>vchar <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> wsp <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> lf <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> cr <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> obsNoWsCtl <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> nullChar<span style="color: green;">&#41;</span>
&nbsp;
cfws <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">$</span> many <span style="color: green;">&#40;</span>comment <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> fws<span style="color: green;">&#41;</span>
fws <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>many1 wsp <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> optional <span style="color: green;">&#40;</span>crlf <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> many1 wsp<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
	<span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> <span style="color: green;">&#40;</span>many1 <span style="color: green;">&#40;</span>crlf <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> many1 wsp<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> <span style="font-weight: bold;">return</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
&nbsp;
comment <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">$</span> between <span style="color: green;">&#40;</span>char '<span style="color: green;">&#40;</span>'<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>char '<span style="color: green;">&#41;</span>'<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span>
	many <span style="color: green;">&#40;</span>commentContent <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> fws<span style="color: green;">&#41;</span>
commentContent <span style="color: #339933; font-weight: bold;">=</span> commentText <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> quotedPair <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> comment
commentText <span style="color: #339933; font-weight: bold;">=</span> ranges <span style="color: green;">&#91;</span><span style="color: green;">&#91;</span>33<span style="color: #339933; font-weight: bold;">..</span>39<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span>42<span style="color: #339933; font-weight: bold;">..</span>91<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span>93<span style="color: #339933; font-weight: bold;">..</span>126<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">&lt;|&gt;</span> obsNoWsCtl
&nbsp;
nullChar <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">$</span> char '\<span style="color: red;">0</span>'
wsp <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">$</span> oneOf <span style="background-color: #3cb371;">&quot; <span style="background-color: #3cb371; font-weight: bold;">\t</span>&quot;</span>
cr <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">$</span> char '\r'
lf <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">$</span> char '\n'
crlf <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">$</span> cr <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> lf
vchar <span style="color: #339933; font-weight: bold;">=</span> ranges <span style="color: green;">&#91;</span><span style="color: green;">&#91;</span>0x21<span style="color: #339933; font-weight: bold;">..</span>0x7e<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span>
obsNoWsCtl <span style="color: #339933; font-weight: bold;">=</span> ranges <span style="color: green;">&#91;</span><span style="color: green;">&#91;</span>1<span style="color: #339933; font-weight: bold;">..</span>8<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span><span style="color: red;">11</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">12</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span>14<span style="color: #339933; font-weight: bold;">..</span>31<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: green;">&#91;</span><span style="color: red;">127</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span>
ranges <span style="color: #339933; font-weight: bold;">=</span> simply <span style="color: #339933; font-weight: bold;">.</span> oneOf <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">map</span> chr <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">concat</span></pre></div></div>

<p>This now passes all of Dominic Sayer&#8217;s tests that it is meant to—the domain validation used in Dominic Sayer&#8217;s tests is more strict than RFC5322 specifies. Expect this to change!</p>
<p>For those who’d like to know, email addresses that now parse that didn’t before include the often-used (‘|’ is merely to indicate the end of whitespace):</p>
<pre>I.                        |
 am.                  |
 a.      |
 nice.|
 guy@(yeah)you.com</pre>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/email-address-validation-simpler-faster-more-correct/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Properly validating e-mail addresses (or converting EBNF to Parsec)</title>
		<link>http://porg.es/blog/properly-validating-e-mail-addresses</link>
		<comments>http://porg.es/blog/properly-validating-e-mail-addresses#comments</comments>
		<pubDate>Sun, 08 Mar 2009 12:49:52 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[parsec]]></category>
		<category><![CDATA[rfc]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=307</guid>
		<description><![CDATA[Update: See the better code in the next post.
In recent times there have been several calls for websites to properly validate email addresses. Invariably, the compiled regex from Perl’s RFC822 is pasted up as The Way To Do It. The problem with this is (as the source code from the Perl module notes) is that [...]]]></description>
			<content:encoded><![CDATA[<p><i>Update</i>: See the better code in <a href="http://porg.es/blog/email-address-validation-simpler-faster-more-correct">the next post</a>.</p>
<p>In recent times there have been <a href="http://www.reddit.com/r/programming/search?q=email+valid">several calls for websites to properly validate email addresses</a>. Invariably, the compiled <a href="http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html">regex from Perl’s RFC822</a> is pasted up as The Way To Do It. The problem with this is (as the source code from the Perl module notes) is that email addresses <em>cannot</em> be validated by a simple regex (due to requiring parenthesis-matching). The Perl code addresses this by first stripping out all comments and then parsing via regex.</p>
<p>With this in mind, I thought that implementing the Addr-Spec specification from <a href="http://tools.ietf.org/html/rfc5322#section-3.4.1">RFC 5322</a> (only released less than 6 months ago) might be a good test of the Haskell library Parsec. So, without further ado I went ahead and translated the EBNF from RFC 5322 directly into Parsec.</p>
<p>The mapping is something like this:</p>
<dl>
<dt>juxtaposition</dt>
<dd><code>&gt;&gt;</code></dd>
<dt>/</dt>
<dd><code>&lt;|&gt;</code></dd>
<dt>*</dt>
<dd><code>many</code></dd>
<dt>1*</dt>
<dd><code>many1</code></dd>
<dt>[]</dt>
<dd><code>optional</code></dd>
</dl>
<p>Here is the result:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> Text.<span style="color: black;">Parsec</span>
<span style="color: #ff7700;font-weight:bold;">import</span> Text.<span style="color: black;">Parsec</span>.<span style="color: black;">Char</span>
<span style="color: #ff7700;font-weight:bold;">import</span> Data.<span style="color: black;">Char</span> <span style="color: black;">&#40;</span><span style="color: #008000;">chr</span><span style="color: black;">&#41;</span>
&nbsp;
isValid :: String -<span style="color: #66cc66;">&gt;</span> Bool
isValid x = let result = valid x <span style="color: #ff7700;font-weight:bold;">in</span>
	either <span style="color: black;">&#40;</span>const <span style="color: #008000;">False</span><span style="color: black;">&#41;</span> <span style="color: black;">&#40;</span>const <span style="color: #008000;">True</span><span style="color: black;">&#41;</span> result
&nbsp;
valid :: String -<span style="color: #66cc66;">&gt;</span> Either ParseError <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
valid x = parse addrSpec <span style="color: #483d8b;">&quot;&quot;</span> x
&nbsp;
ignore x = x <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
addrSpec = localPart <span style="color: #66cc66;">&gt;&gt;</span> char <span style="color: #483d8b;">'@'</span> <span style="color: #66cc66;">&gt;&gt;</span> domain <span style="color: #66cc66;">&gt;&gt;</span> eof
&nbsp;
localPart = dotAtom <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> quotedString <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> obsLocalPart <span style="color: #66cc66;">&lt;?&gt;</span> <span style="color: #483d8b;">&quot;local part&quot;</span>
domain = dotAtom <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> domainLiteral <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> obsDomain <span style="color: #66cc66;">&lt;?&gt;</span> <span style="color: #483d8b;">&quot;domain&quot;</span>
&nbsp;
domainLiteral = optional cfws <span style="color: #66cc66;">&gt;&gt;</span> char <span style="color: #483d8b;">'['</span> <span style="color: #66cc66;">&gt;&gt;</span>
		many <span style="color: black;">&#40;</span> optional fws <span style="color: #66cc66;">&gt;&gt;</span> dtext<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;&gt;</span>
		optional fws  <span style="color: #66cc66;">&gt;&gt;</span> char <span style="color: #483d8b;">']'</span> <span style="color: #66cc66;">&gt;&gt;</span> optional cfws
		<span style="color: #66cc66;">&lt;?&gt;</span> <span style="color: #483d8b;">&quot;domain literal&quot;</span>
&nbsp;
ranges = oneOf . <span style="color: #008000;">map</span> <span style="color: #008000;">chr</span> . <span style="color: black;">concat</span>
vchar = ranges <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span>0x21..0x7E<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> -- <span style="color: #ff7700;font-weight:bold;">from</span> Backus-Naur RFC
dtext = ranges <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span>33..90<span style="color: black;">&#93;</span>,<span style="color: black;">&#91;</span>94..126<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> obsDtext
qtext = ranges <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">33</span><span style="color: black;">&#93;</span>,<span style="color: black;">&#91;</span>35..91<span style="color: black;">&#93;</span>,<span style="color: black;">&#91;</span>93..126<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> obsQtext
atext = alphaNum <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> oneOf <span style="color: #483d8b;">&quot;!#$%&amp;'*+-/=?^_`{|}~&quot;</span>
ctext = ranges <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span>33..39<span style="color: black;">&#93;</span>,<span style="color: black;">&#91;</span>42..91<span style="color: black;">&#93;</span>,<span style="color: black;">&#91;</span>93..126<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> obsCtext
wsp = char <span style="color: #483d8b;">' '</span>
	<span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> char <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\t</span>'</span>
	<span style="color: #66cc66;">&lt;?&gt;</span> <span style="color: #483d8b;">&quot;space or tab&quot;</span>
&nbsp;
cr = char <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\r</span>'</span> <span style="color: #66cc66;">&lt;?&gt;</span> <span style="color: #483d8b;">&quot;carriage return&quot;</span>
lf = char <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #66cc66;">&lt;?&gt;</span> <span style="color: #483d8b;">&quot;line feed&quot;</span>
crlf = cr <span style="color: #66cc66;">&gt;&gt;</span> lf <span style="color: #66cc66;">&lt;?&gt;</span> <span style="color: #483d8b;">&quot;CRLF line ending&quot;</span>
&nbsp;
-- <span style="color: #808080; font-style: italic;"># modification: added try</span>
cfws = <span style="color: #ff7700;font-weight:bold;">try</span> <span style="color: black;">&#40;</span>many1 <span style="color: black;">&#40;</span>optional fws <span style="color: #66cc66;">&gt;&gt;</span> comment<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;&gt;</span> optional fws<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> ignore fws
-- <span style="color: #808080; font-style: italic;"># modification from RFC: adding try because of overlap</span>
fws = <span style="color: #ff7700;font-weight:bold;">try</span> <span style="color: black;">&#40;</span>optional <span style="color: black;">&#40;</span>many wsp <span style="color: #66cc66;">&gt;&gt;</span> crlf<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;&gt;</span> many1 wsp<span style="color: black;">&#41;</span>
	<span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> many1 wsp
	<span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> obsFws
&nbsp;
-- <span style="color: #808080; font-style: italic;"># modification: added try</span>
comment = between <span style="color: black;">&#40;</span>char <span style="color: #483d8b;">'('</span><span style="color: black;">&#41;</span> <span style="color: black;">&#40;</span>char <span style="color: #483d8b;">')'</span><span style="color: black;">&#41;</span> <span style="color: black;">&#40;</span>many <span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">try</span> <span style="color: black;">&#40;</span>optional fws <span style="color: #66cc66;">&gt;&gt;</span> ccontent<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;&gt;</span> optional fws<span style="color: black;">&#41;</span>
	<span style="color: #66cc66;">&lt;?&gt;</span> <span style="color: #483d8b;">&quot;comment&quot;</span>
ccontent = ignore ctext
	<span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> ignore quotedPair
	<span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> comment
&nbsp;
atom = optional cfws <span style="color: #66cc66;">&gt;&gt;</span> many1 atext <span style="color: #66cc66;">&gt;&gt;</span> optional cfws
dotAtomText = many1 atext <span style="color: #66cc66;">&gt;&gt;</span> many <span style="color: black;">&#40;</span>char <span style="color: #483d8b;">'.'</span> <span style="color: #66cc66;">&gt;&gt;</span> many1 atext<span style="color: black;">&#41;</span>
dotAtom = optional cfws <span style="color: #66cc66;">&gt;&gt;</span> dotAtomText <span style="color: #66cc66;">&gt;&gt;</span> optional cfws
&nbsp;
-- <span style="color: #808080; font-style: italic;"># other change from RFC -- merge prefix</span>
quotedPair = char <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>vchar <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> wsp<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> obsQp<span style="color: black;">&#41;</span>
qcontent = qtext <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> quotedPair
quotedString = optional cfws <span style="color: #66cc66;">&gt;&gt;</span>	char <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #66cc66;">&gt;&gt;</span> many <span style="color: black;">&#40;</span>optional fws <span style="color: #66cc66;">&gt;&gt;</span> qcontent<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;&gt;</span>
	optional fws <span style="color: #66cc66;">&gt;&gt;</span>	char <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #66cc66;">&gt;&gt;</span> optional cfws
	<span style="color: #66cc66;">&lt;?&gt;</span> <span style="color: #483d8b;">&quot;quoted string&quot;</span>
&nbsp;
-- <span style="color: #808080; font-style: italic;"># Obsolete syntax</span>
obsNoWsCtl = ranges <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span>1..8<span style="color: black;">&#93;</span>,<span style="color: black;">&#91;</span>11..12<span style="color: black;">&#93;</span>,<span style="color: black;">&#91;</span>14..31<span style="color: black;">&#93;</span>,<span style="color: black;">&#91;</span><span style="color: #ff4500;">127</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>
obsCtext = obsNoWsCtl
obsDtext = obsNoWsCtl <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> quotedPair
obsQtext = obsNoWsCtl
-- <span style="color: #808080; font-style: italic;"># change: see above</span>
obsQp = <span style="color: black;">&#40;</span>char <span style="color: black;">&#40;</span><span style="color: #008000;">chr</span> <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> obsNoWsCtl <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> lf <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> cr<span style="color: black;">&#41;</span>
obsLocalPart = word <span style="color: #66cc66;">&gt;&gt;</span> many <span style="color: black;">&#40;</span>char <span style="color: #483d8b;">'.'</span> <span style="color: #66cc66;">&gt;&gt;</span> word<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
obsDomain = atom <span style="color: #66cc66;">&gt;&gt;</span> many <span style="color: black;">&#40;</span>char <span style="color: #483d8b;">'.'</span> <span style="color: #66cc66;">&gt;&gt;</span> atom<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
obsFws = many1 wsp <span style="color: #66cc66;">&gt;&gt;</span> many <span style="color: black;">&#40;</span>crlf <span style="color: #66cc66;">&gt;&gt;</span> many1 wsp<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
word = atom <span style="color: #66cc66;">&lt;</span>|<span style="color: #66cc66;">&gt;</span> quotedString</pre></div></div>

<p><i>A note before I continue:</i> since Parsec by default does no backtracking (in order to remain efficient), there are a couple of places (two that I&#8217;ve found so far) where the original EBNF needs to be changed slightly. I have noted these in the source above. It is possible there are a couple more places that need fixing, but I haven’t run this against a large test suite yet to find them. (They are most likely to be in the ‘obsolete syntax’ section.)</p>
<p>And of course, some demonstrations (keep in mind that there is an extra level of escaping operating here&#8230; where relevant I&#8217;ve included the unescaped email address in a comment):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">isValid <span style="color: #483d8b;">&quot;porges@example.com&quot;</span> == <span style="color: #008000;">True</span>
isValid <span style="color: #483d8b;">&quot;porges@@example.com&quot;</span> == <span style="color: #008000;">False</span>
isValid <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>porges@<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span> == <span style="color: #008000;">True</span> -- <span style="color: #808080; font-style: italic;"># &quot;porges@&quot;@porg.es</span>
isValid <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>por(g)es@<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span> == <span style="color: #008000;">True</span> -- <span style="color: #808080; font-style: italic;"># &quot;por(g)es@&quot;@porg.es</span>
isValid <span style="color: #483d8b;">&quot;porges(comment)@example.com&quot;</span> == <span style="color: #008000;">True</span>
isValid <span style="color: #483d8b;">&quot;porges(comme(nests)nt)@example.com&quot;</span> == <span style="color: #008000;">True</span>
isValid <span style="color: #483d8b;">&quot;porges(comme(nests)nt())@example.com&quot;</span> == <span style="color: #008000;">True</span>
isValid <span style="color: #483d8b;">&quot;porges(()comme(nests)nt())@example.com&quot;</span> == <span style="color: #008000;">True</span>
isValid <span style="color: #483d8b;">&quot;()porges(()comme(nests)nt())@example.com&quot;</span> == <span style="color: #008000;">True</span>
isValid <span style="color: #483d8b;">&quot;((lol)porges(()comme(nests)nt())@example.com&quot;</span> == <span style="color: #008000;">False</span>
isValid <span style="color: #483d8b;">&quot;((lol))porges(()comme(nests)nt())@example.com&quot;</span> == <span style="color: #008000;">True</span>
isValid <span style="color: #483d8b;">&quot;(lol))porges(()comme(nests)nt())@example.com&quot;</span> == <span style="color: #008000;">False</span>
isValid <span style="color: #483d8b;">&quot;((lol))porges(()comme(nests)nt())@example.com&quot;</span> == <span style="color: #008000;">True</span>
isValid <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>s<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\0</span><span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span> == <span style="color: #008000;">True</span>
-- <span style="color: #808080; font-style: italic;"># &quot;s\NUL&quot;@example.com, where NUL is actually the</span>
-- <span style="color: #808080; font-style: italic;"># null character! Yep, can't strlen() on email addresses...</span></pre></div></div>

<p>I managed to find <a href="http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx">this post on email addresses</a> by Phil Haack which has the following tests:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>Abc<span style="color: #000099; font-weight: bold;">\\</span>@def<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>Fred Bloggs<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>Joe<span style="color: #000099; font-weight: bold;">\\</span>Blow<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>Abc@def<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;customer/department=shipping@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;$A12345@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;!def!xyz%abc@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;_somename@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;NotAnEmail&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;@NotAnEmail&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>test<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>blah<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>test<span style="color: #000099; font-weight: bold;">\\</span>blah<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
-- <span style="color: #808080; font-style: italic;"># Phil gets false for this, which I think is wrong</span>
-- <span style="color: #808080; font-style: italic;"># (Dominic Sayers notes the same at the end of the comment thread)</span>
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>test<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\r</span>blah<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>test<span style="color: #000099; font-weight: bold;">\r</span>blah<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>test<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\&quot;</span>blah<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>test<span style="color: #000099; font-weight: bold;">\&quot;</span>blah<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;customer/department@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;$A12345@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;!def!xyz%abc@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;_Yosemite.Sam@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;~@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;.wooly@example.com&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;wo..oly@example.com&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;pootietang.@example.com&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;.@example.com&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>Austin@Powers<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Ima.Fool@example.com&quot;</span>,<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>Ima.Fool<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>Ima Fool<span style="color: #000099; font-weight: bold;">\&quot;</span>@example.com&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Ima Fool@example.com&quot;</span>,<span style="color: #008000;">False</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></pre></div></div>

<p>Next job is to test it against <a href="http://www.dominicsayers.com/isemail/">this batch&#8230;</a></p>
<p><i>Update:</i> Yep, fails in several areas with the obsolete syntax. I’ve fixed one above. (Note that I’m not concerned with the failures in the domain part of the address, as the RFC5322 EBNF for this is more liberal than the tests require.)</p>
<p>Might have to refactor the syntax&#8230; there is a large overlap with the obsolete syntax. (Or just use ‘try’, but that’s not so efficient.)</p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/properly-validating-e-mail-addresses/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Is it just me?</title>
		<link>http://porg.es/blog/is-it-just-me</link>
		<comments>http://porg.es/blog/is-it-just-me#comments</comments>
		<pubDate>Sat, 07 Mar 2009 01:17:48 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[commentary]]></category>
		<category><![CDATA[bain]]></category>
		<category><![CDATA[gothic]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[silly]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=304</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><img src="http://porg.es/blog/wp-content/uploads/2009/03/woah.png" alt="American Bain" title="American Bain" width="454" height="198" class="alignnone size-full wp-image-305" /></p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/is-it-just-me/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making Maya&#8217;s Python palatable</title>
		<link>http://porg.es/blog/making-mayas-python-palatable</link>
		<comments>http://porg.es/blog/making-mayas-python-palatable#comments</comments>
		<pubDate>Tue, 03 Mar 2009 04:57:12 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[criticism]]></category>
		<category><![CDATA[maya]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[short]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=300</guid>
		<description><![CDATA[Maya&#8217;s python interface leaves something to be desired, as it seems like a straight port of their existing MEL interface with no additional thought put into designing a nice OO interface. For example, here is how to set or get the ‘radius’ attribute of a sphere:

s = cmds.sphere&#40;&#41;
r = cmds.sphere&#40;s, query=True, radius=True&#41;
cmds.sphere&#40;s, edit=True, radius=10&#41;

Nasty.
So, here [...]]]></description>
			<content:encoded><![CDATA[<p>Maya&#8217;s python interface leaves something to be desired, as it seems like a straight port of their existing MEL interface with no additional thought put into designing a nice OO interface. For example, here is how to set or get the ‘<code>radius</code>’ attribute of a sphere:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">s = cmds.<span style="color: black;">sphere</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
r = cmds.<span style="color: black;">sphere</span><span style="color: black;">&#40;</span>s, query=<span style="color: #008000;">True</span>, radius=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
cmds.<span style="color: black;">sphere</span><span style="color: black;">&#40;</span>s, edit=<span style="color: #008000;">True</span>, radius=<span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Nasty.</p>
<p>So, here is a wrapper to make things nicer:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> maya.<span style="color: black;">cmds</span> <span style="color: #ff7700;font-weight:bold;">as</span> cmds
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Wrapper<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, other<span style="color: black;">&#41;</span>:
		<span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'me'</span><span style="color: black;">&#93;</span> = other<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__getattr__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, thing<span style="color: black;">&#41;</span>:
		i = <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">if</span> cmds.<span style="color: black;">attributeQuery</span><span style="color: black;">&#40;</span>thing, node=<span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'me'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, exists=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: #ff4500;">1</span>
		<span style="color: #ff7700;font-weight:bold;">return</span> cmds.<span style="color: black;">getAttr</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'me'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;.&quot;</span> + thing<span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__setattr__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, thing, value<span style="color: black;">&#41;</span>:
		i = <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">if</span> cmds.<span style="color: black;">attributeQuery</span><span style="color: black;">&#40;</span>thing, node=<span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'me'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, exists=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: #ff4500;">1</span>
		cmds.<span style="color: black;">setAttr</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'me'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;.&quot;</span> + name, value<span style="color: black;">&#41;</span></pre></div></div>

<p>The above example is now:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">s = Wrapper<span style="color: black;">&#40;</span>cmds.<span style="color: black;">sphere</span><span style="color: black;">&#41;</span>
r = s.<span style="color: black;">radius</span>
s.<span style="color: black;">radius</span> = <span style="color: #ff4500;">10</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/making-mayas-python-palatable/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Annoyances with Intrepid</title>
		<link>http://porg.es/blog/annoyances-with-intrepid</link>
		<comments>http://porg.es/blog/annoyances-with-intrepid#comments</comments>
		<pubDate>Thu, 26 Feb 2009 22:30:16 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[commentary]]></category>
		<category><![CDATA[annoyance]]></category>
		<category><![CDATA[ati]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[compiz]]></category>
		<category><![CDATA[criticism]]></category>
		<category><![CDATA[dvd]]></category>
		<category><![CDATA[intrepid]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=297</guid>
		<description><![CDATA[After having just installed Intrepid on a friend’s PC last night:

I ran into this bug (here’s the fix)
ATi’s dual monitor setup is still too hard (here’s how to do it)
ATi’s drivers can’t do compiz and video at the same time (Install the latest drivers to fix it)

]]></description>
			<content:encoded><![CDATA[<p>After having just installed Intrepid on a friend’s PC last night:</p>
<ul>
<li>I ran into <a href="https://bugs.launchpad.net/ubuntu/+source/mplayer/+bug/197068">this bug</a> (<a href="http://ubuntuforums.org/showpost.php?p=5014367&#038;postcount=4">here’s the fix</a>)</li>
<li>ATi’s dual monitor setup is still too hard (<a href="http://ubuntuforums.org/showpost.php?p=4486852&#038;postcount=6">here’s how to do it</a>)</li>
<li>ATi’s drivers can’t do compiz and video at the same time (<a href="http://wiki.cchtml.com/index.php/Ubuntu_Intrepid_Installation_Guide#Installing_the_restricted_drivers_manually">Install the latest drivers to fix it</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/annoyances-with-intrepid/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parametrizing Monoids and Monads</title>
		<link>http://porg.es/blog/parametrizing-monoids-and-monads</link>
		<comments>http://porg.es/blog/parametrizing-monoids-and-monads#comments</comments>
		<pubDate>Mon, 16 Feb 2009 05:10:19 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[arity]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[criticism]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[indexed]]></category>
		<category><![CDATA[monad]]></category>
		<category><![CDATA[monads]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=284</guid>
		<description><![CDATA[Dan Piponi’s latest post “Beyond Monads” has prompted some wonderment (and forehead-slapping). For example:
How did we all miss that before?
—Peaker
The answer (of course!) is that while we might have, they didn&#8217;t.  For example, Edward Kmett’s category-extras package has had Control.Monad.Indexed available for use in Haskell since early last year, while the concept for its [...]]]></description>
			<content:encoded><![CDATA[<p>Dan Piponi’s latest post “<a href="http://blog.sigfpe.com/2009/02/beyond-monads.html">Beyond Monads</a>” has prompted some wonderment (and forehead-slapping). For example:</p>
<blockquote><p>How did we all miss that before?<img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
<p style="text-align:right">—<cite><a href="http://www.reddit.com/r/haskell/comments/7xi0r/a_neighborhood_of_infinity_beyond_monads/c07ohx9">Peaker</a></cite></p></blockquote>
<p>The answer (of course!) is that while <em>we</em> might have, <em>they</em> didn&#8217;t. <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /> For example, Edward Kmett’s <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/category-extras-0.53.5">category-extras</a> package has had <a href="http://hackage.haskell.org/packages/archive/category-extras/0.53.5/doc/html/Control-Monad-Indexed.html">Control.Monad.Indexed</a> available for use in Haskell since early last year, while the concept for its implementation in Haskell has been around since at least 2005 (see the paper “<a href="http://crab.rutgers.edu/~pjohann/f14-ghani.pdf">Monadic Augment and Generalised Short Cut Fusion</a>”). Needless to say, Oleg has <a href="http://okmij.org/ftp/Computation/monads.html#param-monad">been there</a> too.</p>
<p>For me, this prompted a vaguely-related revelation. Say that we have a Category class:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">class</span> Category <span style="color: green;">&#40;</span>⤳<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
	<span style="font-weight: bold;">id</span> ∷ a ⤳ a
	<span style="color: green;">&#40;</span>∘<span style="color: green;">&#41;</span> ∷ <span style="color: green;">&#40;</span>b ⤳ c<span style="color: green;">&#41;</span> → <span style="color: green;">&#40;</span>a ⤳ b<span style="color: green;">&#41;</span> → <span style="color: green;">&#40;</span>a ⤳ c<span style="color: green;">&#41;</span></pre></div></div>

<p>I had recently been wondering how categories other than (→), such as graphs (and even the trivial category) fit into this model. Now that I have figured it out, the answer is simple; it is a matter of arity. Graphs and other datastructure-related categories don’t have the extra type arguments (unless you’re working in a dependently-typed language), and so can’t fit into this. What we want to do is <em>fake</em> the extra arguments, by having some extra ones that we can just ignore (the name, FF, is short for FakeFake, i.e. two fake arguments).</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">newtype</span> FF f a b <span style="color: #339933; font-weight: bold;">=</span> FF <span style="color: green;">&#123;</span> unFF <span style="color: #339933; font-weight: bold;">::</span> f <span style="color: green;">&#125;</span></pre></div></div>

<p>Now we can define the trivial category!</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">class</span> Category <span style="color: green;">&#40;</span>FF <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
	<span style="font-weight: bold;">id</span> <span style="color: #339933; font-weight: bold;">=</span> FF <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
	f ∘ g <span style="color: #339933; font-weight: bold;">=</span> FF <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span></pre></div></div>

<p>Viewed in this light, it is obvious why (as Dan notes in the original post) Monoids give rise to Monads and Categories give rise to ParametrizedMonads, as we have:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">class</span> Monoid m ⇒ Category <span style="color: green;">&#40;</span>FF m<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
	<span style="font-weight: bold;">id</span> <span style="color: #339933; font-weight: bold;">=</span> FF mempty
	<span style="color: green;">&#40;</span>FF f<span style="color: green;">&#41;</span> ∘ <span style="color: green;">&#40;</span>FF g<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> FF <span style="color: green;">&#40;</span>mappend f g<span style="color: green;">&#41;</span></pre></div></div>

<p>Next, we want to write implementations for all our old Monads in the new PMonad class. We might do it like this (with a new newtype for the different arguments of this datatype, RealFakeFakeReal):</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">newtype</span> RFFR f x y a <span style="color: #339933; font-weight: bold;">=</span> RFFR <span style="color: green;">&#123;</span> unRFFR ∷ <span style="color: green;">&#40;</span>f a<span style="color: green;">&#41;</span> <span style="color: green;">&#125;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">class</span> PMonad m <span style="color: #06c; font-weight: bold;">where</span>
	<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&gt;&gt;=</span><span style="color: green;">&#41;</span> ∷ m s1 s2 a → <span style="color: green;">&#40;</span>a → m s2 s3 b<span style="color: green;">&#41;</span> → m s1 s3 b
	<span style="font-weight: bold;">return</span> ∷ a → m s s a
&nbsp;
<span style="color: #06c; font-weight: bold;">instance</span> <span style="color: green;">&#40;</span>Old<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Monad</span> m<span style="color: green;">&#41;</span> ⇒ PMonad <span style="color: green;">&#40;</span>RFFR m<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
	<span style="color: green;">&#40;</span>RFFR x<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> f <span style="color: #339933; font-weight: bold;">=</span> RFFR <span style="color: green;">&#40;</span>x Old<span style="color: #339933; font-weight: bold;">.&gt;&gt;=</span> unRFFR ∘ f<span style="color: green;">&#41;</span>
	<span style="font-weight: bold;">return</span> x <span style="color: #339933; font-weight: bold;">=</span> RFFR <span style="color: green;">&#40;</span>Old<span style="color: #339933; font-weight: bold;">.</span><span style="font-weight: bold;">return</span> x<span style="color: green;">&#41;</span></pre></div></div>

<p>There is a big issue that this highlights. It is <em>hard</em> to work with types of different arities in Haskell. (This is noted in the ‘<a href="http://haskell.org/haskellwiki/Quantified_contexts">quantified contexts</a>’ proposal.)</p>
<p>As an example, since we now know that every Monoid is a Category, we might think to drop Monoids and just use Categories everywhere (I should note that this is actually a silly idea <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_razz.gif" alt="" />!). Unfortunately, we can’t just do this as we’ll have to use <code>FF</code> wrappers/unwrappers everywhere:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">x <span style="color: #339933; font-weight: bold;">=</span> unFF <span style="color: #339933; font-weight: bold;">$</span> FF <span style="color: green;">&#91;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: green;">&#93;</span> ∘ FF <span style="color: green;">&#91;</span><span style="color: red;">4</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">5</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">6</span><span style="color: green;">&#93;</span></pre></div></div>

<p>I have not yet found a workaround for this. Help would be nice <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/parametrizing-monoids-and-monads/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cleaning up a set of tags with Awk</title>
		<link>http://porg.es/blog/cleaning-up-a-set-of-tags-with-awk</link>
		<comments>http://porg.es/blog/cleaning-up-a-set-of-tags-with-awk#comments</comments>
		<pubDate>Wed, 28 Jan 2009 02:08:05 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[commentary]]></category>
		<category><![CDATA[replies]]></category>
		<category><![CDATA[utility]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[inflammatory]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=266</guid>
		<description><![CDATA[Introduction
David R. MacIver has recently written this blog post about cleaning up a set of tags. This blog post, on the other hand, is about a nice old Unix tool called ‘awk’.
Awk is one of those programs that is often overlooked. It is really a small domain-specific language for processing text. In some ways it [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p><a href="http://www.drmaciver.com/about/">David R. MacIver</a> has recently written <a href="http://www.drmaciver.com/2009/01/cleaning-up-a-set-of-tags-part-1/">this blog post about cleaning up a set of tags</a>. <i>This</i> blog post, on the other hand, is about a nice old Unix tool called ‘awk’.</p>
<p>Awk is one of those programs that is often overlooked. It is really a small domain-specific language for processing text. In some ways it resembles sed, but it is more powerful, and it especially excels at processing line- and field-structured input.</p>
<h3>Processing cite-u-like&#8217;s data</h3>
<p>First of all, before we begin I want to say this this isn&#8217;t a criticism of David&#8217;s work. Using a general-purpose language like Ruby to process data comes with several benefits. This post is to explain the benefits of awk and what it excels at doing.</p>
<p>Now, cite-u-like&#8217;s tag data comes in a pipe-separated format, so we have input like this:</p>
<pre style="overflow:auto">42|61baaeba8de136d9c1aa9c18ec3860e8|2004-11-04 02:25:05.373798+00|ecoli
42|61baaeba8de136d9c1aa9c18ec3860e8|2004-11-04 02:25:05.373798+00|metabolism
42|61baaeba8de136d9c1aa9c18ec3860e8|2004-11-04 02:25:05.373798+00|barabasi
42|61baaeba8de136d9c1aa9c18ec3860e8|2004-11-04 02:25:05.373798+00|networks
43|61baaeba8de136d9c1aa9c18ec3860e8|2004-11-04 02:25:51.839281+00|control
43|61baaeba8de136d9c1aa9c18ec3860e8|2004-11-04 02:25:51.839281+00|engineering
43|61baaeba8de136d9c1aa9c18ec3860e8|2004-11-04 02:25:51.839281+00|robustness
44|61baaeba8de136d9c1aa9c18ec3860e8|2004-11-04 02:26:33.156319+00|networks
44|61baaeba8de136d9c1aa9c18ec3860e8|2004-11-04 02:26:33.156319+00|strogatz
44|61baaeba8de136d9c1aa9c18ec3860e8|2004-11-04 02:26:33.156319+00|survey</pre>
<p>From now on, whenever you see <i>x</i>-separated data, I want you to scream ‘USE AWK!’ <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_razz.gif" alt="" /></p>
<p>Awk scripts look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">pattern { expression }</pre></div></div>

<p><i>pattern</i> is used to match against a record, and if successful, the action in the braces (<i>expression</i>) will be carried out. But what is a record? Awk allows you to define what a line is using the variable <code>RS</code> (short for ‘record separator’). By default it is set to <code>\n</code> (so that each line is a record), which is what we want here.</p>
<p>Within the expression you can refer to <i>fields</i> of the current record, using the syntax <code>$<i>n</i></code>. <code>$0</code> refers to the whole record, while <code>$1</code>,<code>$2</code>&#8230; refer to individual fields.</p>
<p>Awk also allows you to define what the <i>field separator</i> will be via the variable <code>FS</code>.</p>
<p>So how do we set these variables? Awk has two special patterns <code>BEGIN</code> and <code>END</code>, which run before and after everything else. In this case, we want the fields to be separated by <code>|</code>, so we use the pattern:</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">BEGIN { FS = &quot;|&quot; }</pre></div></div>

<p>This is rather long-winded, so mawk (an implementation of awk) also allows you to set <code>FS</code> via a command-line option <code>-F</code>.</p>
<p>For this application, we want the last field of the record (we could hard-code it as <code>$4</code>, but we&#8217;re exploring awk!). Awk provides the number of fields in the record as the variable <code>NF</code> (number of fields), so we want to access this field. We do so using the record syntax <code>$</code> and the variable <code>NF</code>.</p>
<p>So to put all this together, what we want is the command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #ff0000;">&quot;|&quot;</span> <span style="color: #ff0000;">'{ print $NF }'</span></pre></div></div>

<p>We set the field separator to &#8220;|&#8221;, and write an awk expression to print the last field of each record. Since we left the <i>pattern</i> empty, this expression is evaluated on every record.</p>
<h3>Awk vs. Ruby</h3>
<p>So what good is learning all this, anyway? There are a couple of reasons:</p>
<ul>
<li>awk is standard on *nix operating systems. In order to use David&#8217;s code I had to install Ruby; with awk you can generally count on it being there.</li>
<li>awk is <em>fast</em> (I should say at least in the interpreter ‘mawk’ which is the standard for Ubuntu). On my machine the awk version completes in under a third of the time that it takes for David&#8217;s Ruby version to complete. An interesting thing was that the awk version didn&#8217;t even max out the CPU, indicating that it is IO-bound and would go faster if I had faster disks (I&#8217;m currently on a laptop).</li>
<li>Awk is ideal for record- and field-based input, as I hope this post will show you <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></li>
</ul>
<h3>Filtering data with awk</h3>
<p>After the above we use <code>sort</code> and <code>uniq</code> the same as David does to get the results in the following form:</p>
<pre> 212595 bibtex-import
 157136 no-tag
  27926 elegans
  27887 celegans
  27825 c_elegans
  27795 nematode
  27738 wormbase
  27736 caenorhabditis_elegans
  18933 review
  15280 all-articles</pre>
<p>David uses the following to filter out lines with no alphabetical content:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ruby <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">'puts $_ if !($_ =~ /^[^a-z]+$/)'</span></pre></div></div>

<p>We can use awk&#8217;s patterns to do the same thing:</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">$0 ~ /[a-zA-Z]/</pre></div></div>

<p>Here we use the <code>~</code> (match) operator to write a pattern that matches only the records with an alphabetical character in them. (Remember that <code>$0</code> refers to the entire record.) Notice also that we can leave off the expression after the pattern, because it defaults to <code>{ print }</code>, which is exactly what we want.</p>
<p>In this case, awk really shines. On my machine it outperforms the Ruby version by a factor of 8–9.</p>
<h3>Programming with awk</h3>
<p>The third task that David does is to consolidate all tags which are differentiated only by hyphens or underscores. That is, ‘a-tag’, ‘atag’, and ‘a_tag’ should all be considered the same. We choose which one to put into the output by whichever one is used the most times (and then we normalize the tag by replacing ‘-’ with ‘_’ so there are only underscores in the output).</p>
<p>Here is David&#8217;s code to do the job:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">tag_counts = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
STDIN.<span style="color:#9900CC;">lines</span>.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>l<span style="color:#006600; font-weight:bold;">|</span> c, t = l.<span style="color:#CC0066; font-weight:bold;">split</span>; tag_counts<span style="color:#006600; font-weight:bold;">&#91;</span>t.<span style="color:#9900CC;">strip</span><span style="color:#006600; font-weight:bold;">&#93;</span> = c.<span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
duplicates = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>h, k<span style="color:#006600; font-weight:bold;">|</span> h<span style="color:#006600; font-weight:bold;">&#91;</span>k<span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
tag_counts.<span style="color:#9900CC;">keys</span>.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>k<span style="color:#006600; font-weight:bold;">|</span> duplicates<span style="color:#006600; font-weight:bold;">&#91;</span>k.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/-|</span>_<span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> k <span style="color:#006600; font-weight:bold;">&#125;</span>
duplicates.<span style="color:#9900CC;">values</span>.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>vs<span style="color:#006600; font-weight:bold;">|</span> vs.<span style="color:#9900CC;">sort</span>!<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x, y<span style="color:#006600; font-weight:bold;">|</span> tag_counts<span style="color:#006600; font-weight:bold;">&#91;</span>y<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;=&gt;</span> tag_counts<span style="color:#006600; font-weight:bold;">&#91;</span>x<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
new_tag_counts = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
duplicates.<span style="color:#9900CC;">values</span>.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>vs<span style="color:#006600; font-weight:bold;">|</span> new_tag_counts<span style="color:#006600; font-weight:bold;">&#91;</span>vs<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>_<span style="color:#006600; font-weight:bold;">|-</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">+/</span>, <span style="color:#996600;">&quot;_&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = vs.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>v<span style="color:#006600; font-weight:bold;">|</span> tag_counts<span style="color:#006600; font-weight:bold;">&#91;</span>v<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">inject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span>, <span style="color:#006600; font-weight:bold;">&amp;</span>:<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> new_tag_counts.<span style="color:#9900CC;">to_a</span>.<span style="color:#9900CC;">sort</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x, y<span style="color:#006600; font-weight:bold;">|</span> y<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;=&gt;</span> x<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>t, c<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#996600;">&quot; #{c} #{t}&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>I&#8217;m not going to explain it here, because that&#8217;s not the point of the post <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
<p>Here&#8217;s my awk script:</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">{ tag_counts[$2] = $1 }
END {
	for (tag in tag_counts)
	{
		normtag=tag
		gsub(/-|_/,&quot;&quot;,normtag)
&nbsp;
		count=tag_counts[tag]
		sum[normtag]+=count
&nbsp;
		if (count &gt; max[normtag])
		{
			names[normtag]=tag
			max[normtag]=count
		}
	}
&nbsp;
	for (tag in names)
	{
		finaltag=names[tag]
		gsub(/(-|_)+/,&quot;_&quot;,finaltag)
		print &quot; &quot; sum[tag] &quot; &quot; finaltag
	}
}</pre></div></div>

<p>That&#8217;s right, you can use awk to do some ordinary programming tasks! Arrays are used using the usual syntax, and awk even has a foreach-style loop for looping over them. I&#8217;ll walk through the rest of the script slowly.</p>
<p>First we apply an expression to each record, creating an array of tags and their counts:</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">{ tag_counts[$2] = $1 }</pre></div></div>

<p>Then, once everything has finished (the <code>END</code> pattern), we process this array. For each tag, we do the following:</p>
<ol>
<li>
<p>Normalize the tag (the gsub function overwrites the variable, so we have to make a copy):</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">normtag=tag
gsub(/-|_/,&quot;&quot;,normtag)</pre></div></div>

<p>(Notice the similarity between this and Ruby&#8217;s equivalent <code>normtag.gsub!(/-|_/, "")</code>!)</p>
</li>
<li>
<p>Get the count for that tag and add it to the count for the normalized version:</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">count=tag_counts[tag]
sum[normtag]+=count</pre></div></div>

<p>Like in PHP and Perl, if a value is not present in an array it is automatically added with a default value.</p>
</li>
<li>
<p>Next we check to see if the current tag is the commonest version of the normalized tag, and if so we save its name and count in two other arrays:</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">if (count &gt; max[normtag])
{
	names[normtag]=tag
	max[normtag]=count
}</pre></div></div>

<p>Notice again the usefulness of a default value for nonexistent keys: <code>count > max[normtag]</code> will be true if <code>max[normtag]</code> doesn&#8217;t exist.</p>
</li>
</ol>
<p>Now we have all we need to print out the answer. For each tag we normalize it to the final version (remembering to make a copy):</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">finaltag=names[tag]
gsub(/(-|_)+/,&quot;_&quot;,finaltag)</pre></div></div>

<p>Then we print out the line (concatenation is done by simply juxtaposing variables or strings):</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">print &quot; &quot; sum[tag] &quot; &quot; finaltag</pre></div></div>

<p>If you&#8217;ve been watching closely you&#8217;ll notice there is a small difference between the awk and the Ruby scripts; Ruby sorts before outputting, while the awk version will come out in a non-defined order. This is fine! We can use the standard *nix tool ‘sort’ to sort the lines;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-f</span> consolidate_tags.awk <span style="color: #000000; font-weight: bold;">&lt;</span> tags <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-nr</span> <span style="color: #000000; font-weight: bold;">&gt;</span> fixed_tags</pre></div></div>

<p>(Note that this fits in with the *nix philosophy of ‘do one thing well’ and reusing small components.)</p>
<p>Again, the awk version outperforms the Ruby by a factor of 3–4.</p>
<h3>Reading external commands and files</h3>
<p>Unfortunately there doesn&#8217;t seem to be a command-line stemming program (a quick Perl script would suffice but it isn&#8217;t what we&#8217;re here for!), so I&#8217;ll skip that stage (here&#8217;s one of the aforementioned weaknesses of a non-general-purpose language). Instead we&#8217;ll go straight to implementing stopwords.</p>
<p>Here&#8217;s David&#8217;s Ruby code again:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;set&quot;</span>
&nbsp;
stopwords = <span style="color:#CC00FF; font-weight:bold;">Set</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">*</span>
  <span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;smart.txt&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">lines</span>.<span style="color:#9900CC;">reject</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> x =~ <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#008000; font-style:italic;">#/}.map(&amp;:strip)</span>
<span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
STDIN.<span style="color:#9900CC;">lines</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>l<span style="color:#006600; font-weight:bold;">|</span>
  c, t = l.<span style="color:#CC0066; font-weight:bold;">split</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> l <span style="color:#9966CC; font-weight:bold;">unless</span> stopwords.<span style="color:#9966CC; font-weight:bold;">include</span>? t.<span style="color:#9900CC;">strip</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And here&#8217;s my equivalent in awk:</p>

<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;">BEGIN {
    while (getline &lt; &quot;smart.txt&quot;)
    { stopwords[$0] = 1 }
}
!($2 in stopwords)</pre></div></div>

<p>Here I use the ‘getline’ function which does as its name suggests. We make an array of all the stopwords, with 1 as a placeholder value. The pattern is then short and simple: Print every record where the tag isn&#8217;t in the stopwords (again, we can leave off the expression to print the whole record).</p>
<p><i>Note: There is a discrepancy here: David claims this eliminated 46 tags, while I get a value of 368 for both my awk code and his Ruby code.</i></p>
<p>Again, the Ruby takes about 8 times as long to execute.</p>
<h3>Conclusion</h3>
<p>Here&#8217;s a couple of points:</p>
<ul>
<li>
<p>Record- or field-oriented data? Think awk.</p>
</li>
<li>
<p>Don&#8217;t discount it just because it&#8217;s <em>venerable</em>. It is very well-suited to its task.</p>
</li>
<li>
<p><code>pattern { expression }</code> syntax is extremely flexible.</p>
</li>
<li>
<p>Awk&#8217;s regular expressions are fast.</p>
</li>
</ul>
<blockquote><p><i>Nowadays everybody wanna talk<br />
&nbsp;&nbsp;&nbsp;&nbsp;like they got something to say<br />
But nothing comes out<br />
&nbsp;&nbsp;&nbsp;&nbsp;when they move their lips<br />
Just a bunch of gibberish<br />
And motherf—kers act<br />
&nbsp;&nbsp;&nbsp;&nbsp;like they forgot about Awk</i></p>
</blockquote>
<p><img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_biggrin.gif" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/cleaning-up-a-set-of-tags-with-awk/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Refactoring in Haskell: Adding an Argument</title>
		<link>http://porg.es/blog/refactoring-in-haskell-adding-an-argument</link>
		<comments>http://porg.es/blog/refactoring-in-haskell-adding-an-argument#comments</comments>
		<pubDate>Wed, 10 Dec 2008 03:44:47 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[Functional programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[short]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=258</guid>
		<description><![CDATA[Just a small tip on this: When you add an argument to a function that already exists you should check the existing usage of the function. Say you have this:

f x y z = ...

&#8230; and you want:

f x y z w = ...

First of all you should check the contexts where f is used. [...]]]></description>
			<content:encoded><![CDATA[<p>Just a small tip on this: When you add an argument to a function that already exists you should check the existing usage of the function. Say you have this:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">f x y z <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #339933; font-weight: bold;">...</span></pre></div></div>

<p>&#8230; and you want:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">f x y z w <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #339933; font-weight: bold;">...</span></pre></div></div>

<p>First of all you should check the contexts where <code>f</code> is used. For example, if <code>f</code> is quite often used as an argument to <code>map</code> (<code>fmap</code>, <code>&lt;$&gt;</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">elsewhere xs <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>f a b<span style="color: green;">&#41;</span> xs</pre></div></div>

<p>If you naïvely add <code>w</code> to the end of the argument list you&#8217;ll end up with this instead:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">elsewhere xs <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>\x<span style="color: #339933; font-weight: bold;">-&gt;</span> f a b x c<span style="color: green;">&#41;</span> xs</pre></div></div>

<p>On the other hand, if you take a look at the usage of <code>f</code> you can decide that because <code>f</code> is often used to <code>map</code> over things, you can insert the additional parameter <em>before</em> the last, and end up with nicer code:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">elsewhere xs <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>f a b c<span style="color: green;">&#41;</span> xs</pre></div></div>

<p>You may even discover that the existing <code>f</code> is used in a lot of lambdas that could be avoided by rearranging its arguments!</p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/refactoring-in-haskell-adding-an-argument/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Employable</title>
		<link>http://porg.es/blog/employable</link>
		<comments>http://porg.es/blog/employable#comments</comments>
		<pubDate>Sun, 30 Nov 2008 23:09:20 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[self]]></category>
		<category><![CDATA[hireme]]></category>
		<category><![CDATA[job]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=254</guid>
		<description><![CDATA[If there&#8217;s anyone in Auckland who&#8217;d like to hire a 3rd-year undergraduate student over summer (until the end of February), that would be sweet 
]]></description>
			<content:encoded><![CDATA[<p>If there&#8217;s anyone in Auckland who&#8217;d like to hire a 3rd-year undergraduate student over summer (until the end of February), that would be sweet <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_wink.gif" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/employable/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presenting Meteoroids</title>
		<link>http://porg.es/blog/presenting-meteoroids</link>
		<comments>http://porg.es/blog/presenting-meteoroids#comments</comments>
		<pubDate>Wed, 19 Nov 2008 23:23:37 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[self]]></category>
		<category><![CDATA[university]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[massey]]></category>
		<category><![CDATA[meteoroids]]></category>
		<category><![CDATA[uni]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=244</guid>
		<description><![CDATA[This post brought to you as part of fulfilling the requirements for Massey University’s 143.362.
I thought I had posted this earlier, but it turns out I hadn&#8217;t. So, it&#8217;s here now 
Meteoroids
Meteoroids is a simple game (the premise being an homage to the classic Asteroids-based titles), programmed in Processing. Audio is provided via ChucK, and [...]]]></description>
			<content:encoded><![CDATA[<p><i>This post brought to you as part of fulfilling the requirements for Massey University’s <a href="http://www.massey.ac.nz/massey/study/programme-course-and-paper-search/paper.cfm?paper_code=143.362">143.362</a>.</i></p>
<p>I thought I had posted this earlier, but it turns out I hadn&#8217;t. So, it&#8217;s here now <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_razz.gif" alt="" /></p>
<h3>Meteoroids</h3>
<p>Meteoroids is a simple game (the premise being an homage to the classic Asteroids-based titles), programmed in <a href="http://processing.org/">Processing</a>. Audio is provided via <a href="http://chuck.cs.princeton.edu/">ChucK</a>, and input is provided by a Nintendo Wiimote via <a href="http://en.wikipedia.org/wiki/OpenSound_Control">OSC</a> commands generated from <a href="http://code.google.com/p/darwiinosc/">an extension</a> of <a href="http://sourceforge.net/projects/darwiin-remote/">Darwiin Remote</a>.</p>
<p>To explain more, here&#8217;s a short video <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/_NdgujV3z5c&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/_NdgujV3z5c&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/presenting-meteoroids/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vacuuming Firefox&#8217;s sqlite3 databases</title>
		<link>http://porg.es/blog/vacuuming-firefoxs-sqlite3-databases</link>
		<comments>http://porg.es/blog/vacuuming-firefoxs-sqlite3-databases#comments</comments>
		<pubDate>Sun, 16 Nov 2008 23:56:39 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[short]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=239</guid>
		<description><![CDATA[Firefox 3 was running very slow for me, so I desperately tried this, thinking that it wouldn&#8217;t make much difference. I was wrong; there was a noticeable speed improvement. From a bash shell:

find ~/.mozilla -iname '*.sqlite' -execdir sqlite3 &#123;&#125; 'vacuum;' \;

]]></description>
			<content:encoded><![CDATA[<p>Firefox 3 was running very slow for me, so I desperately tried this, thinking that it wouldn&#8217;t make much difference. I was wrong; there was a noticeable speed improvement. From a bash shell:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> ~<span style="color: #000000; font-weight: bold;">/</span>.mozilla <span style="color: #660033;">-iname</span> <span style="color: #ff0000;">'*.sqlite'</span> <span style="color: #660033;">-execdir</span> sqlite3 <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #ff0000;">'vacuum;'</span> \;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/vacuuming-firefoxs-sqlite3-databases/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating x86 assembly with Haskell</title>
		<link>http://porg.es/blog/generating-x86-assembly-with-haskell</link>
		<comments>http://porg.es/blog/generating-x86-assembly-with-haskell#comments</comments>
		<pubDate>Mon, 03 Nov 2008 12:51:14 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[asm]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=236</guid>
		<description><![CDATA[A quick and dirty example:

data Exp = Lit Int -- literal value
	&#124; Call String Exp -- calling a function
	&#124; Bin BinOp Exp Exp -- binary operations
	&#124; Param -- the parameter
	deriving &#40;Show,Eq&#41;
&#160;
data Function = Func String Exp -- a function has a name and expression
data BinOp = Add &#124; Subtract &#124; Multiply &#124; Divide deriving&#40;Show,Eq&#41;
&#160;
-- an [...]]]></description>
			<content:encoded><![CDATA[<p>A quick and dirty example:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Exp <span style="color: #339933; font-weight: bold;">=</span> Lit <span style="color: #cccc00; font-weight: bold;">Int</span> <span style="color: #5d478b; font-style: italic;">-- literal value</span>
	<span style="color: #339933; font-weight: bold;">|</span> Call <span style="color: #cccc00; font-weight: bold;">String</span> Exp <span style="color: #5d478b; font-style: italic;">-- calling a function</span>
	<span style="color: #339933; font-weight: bold;">|</span> Bin BinOp Exp Exp <span style="color: #5d478b; font-style: italic;">-- binary operations</span>
	<span style="color: #339933; font-weight: bold;">|</span> Param <span style="color: #5d478b; font-style: italic;">-- the parameter</span>
	<span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: #cccc00; font-weight: bold;">Eq</span><span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">data</span> Function <span style="color: #339933; font-weight: bold;">=</span> Func <span style="color: #cccc00; font-weight: bold;">String</span> Exp <span style="color: #5d478b; font-style: italic;">-- a function has a name and expression</span>
<span style="color: #06c; font-weight: bold;">data</span> BinOp <span style="color: #339933; font-weight: bold;">=</span> Add <span style="color: #339933; font-weight: bold;">|</span> Subtract <span style="color: #339933; font-weight: bold;">|</span> Multiply <span style="color: #339933; font-weight: bold;">|</span> Divide <span style="color: #06c; font-weight: bold;">deriving</span><span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: #cccc00; font-weight: bold;">Eq</span><span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- an instance to allow us to write nicer definitions</span>
<span style="color: #06c; font-weight: bold;">instance</span> <span style="color: #cccc00; font-weight: bold;">Num</span> Exp <span style="color: #06c; font-weight: bold;">where</span>
	x <span style="color: #339933; font-weight: bold;">*</span> y <span style="color: #339933; font-weight: bold;">=</span> Bin Multiply x y
	x <span style="color: #339933; font-weight: bold;">-</span> y <span style="color: #339933; font-weight: bold;">=</span> Bin Subtract x y
	x <span style="color: #339933; font-weight: bold;">+</span> y <span style="color: #339933; font-weight: bold;">=</span> Bin Add x y
	<span style="font-weight: bold;">fromInteger</span> x <span style="color: #339933; font-weight: bold;">=</span> Lit <span style="color: green;">&#40;</span><span style="font-weight: bold;">fromInteger</span> x<span style="color: green;">&#41;</span>
&nbsp;
outFunc <span style="color: green;">&#40;</span>Func name it<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> name <span style="color: #339933; font-weight: bold;">++</span> <span style="color: #5d478b; font-style: italic;">-- output function name</span>
	<span style="background-color: #3cb371;">&quot;:<span style="background-color: #3cb371; font-weight: bold;">\n</span>push ebp<span style="background-color: #3cb371; font-weight: bold;">\n</span>mov ebp,esp<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: #5d478b; font-style: italic;">-- save old stack frame</span>
	output it <span style="color: #339933; font-weight: bold;">++</span> <span style="color: #5d478b; font-style: italic;">-- output function</span>
	<span style="background-color: #3cb371;">&quot;pop eax<span style="background-color: #3cb371; font-weight: bold;">\n</span>pop ebp<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: #5d478b; font-style: italic;">-- restore old stack frame</span>
	<span style="background-color: #3cb371;">&quot;ret 4<span style="background-color: #3cb371; font-weight: bold;">\n</span><span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span> <span style="color: #5d478b; font-style: italic;">-- remove argument from stack and return</span>
&nbsp;
output <span style="color: green;">&#40;</span>Bin op l r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> outBin op l r <span style="color: #5d478b; font-style: italic;">-- binary operations</span>
output <span style="color: green;">&#40;</span>Lit x<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;push dword &quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="font-weight: bold;">show</span> x <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span> <span style="color: #5d478b; font-style: italic;">-- push literal</span>
output <span style="color: green;">&#40;</span>Param<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;push dword [ebp+8]<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span> <span style="color: #5d478b; font-style: italic;">-- push parameter</span>
output <span style="color: green;">&#40;</span>Call name with<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> output with <span style="color: #339933; font-weight: bold;">++</span>
	<span style="background-color: #3cb371;">&quot;call &quot;</span> <span style="color: #339933; font-weight: bold;">++</span> name <span style="color: #339933; font-weight: bold;">++</span>
	<span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\n</span>push eax<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span> <span style="color: #5d478b; font-style: italic;">-- put return value onto stack</span>
&nbsp;
outBin Add <span style="color: #339933; font-weight: bold;">=</span> outBinGen <span style="background-color: #3cb371;">&quot;add&quot;</span>
outBin Subtract <span style="color: #339933; font-weight: bold;">=</span> outBinGen <span style="background-color: #3cb371;">&quot;sub&quot;</span>
outBin Multiply <span style="color: #339933; font-weight: bold;">=</span> outBinGen <span style="background-color: #3cb371;">&quot;imul&quot;</span>
outBin Divide <span style="color: #339933; font-weight: bold;">=</span> outBinGen <span style="background-color: #3cb371;">&quot;idiv&quot;</span>
&nbsp;
outBinGen op l r <span style="color: #339933; font-weight: bold;">=</span> output l <span style="color: #339933; font-weight: bold;">++</span> output r <span style="color: #339933; font-weight: bold;">++</span>
	<span style="background-color: #3cb371;">&quot;pop ebx<span style="background-color: #3cb371; font-weight: bold;">\n</span>pop eax<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> op <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot; eax,ebx<span style="background-color: #3cb371; font-weight: bold;">\n</span>push eax<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span></pre></div></div>

<p>And an example of using it:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">main <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">putStr</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">concatMap</span> outFunc <span style="color: green;">&#91;</span>double<span style="color: #339933; font-weight: bold;">,</span>quad<span style="color: green;">&#93;</span>
double <span style="color: #339933; font-weight: bold;">=</span> Func <span style="background-color: #3cb371;">&quot;double&quot;</span> <span style="color: green;">&#40;</span>Param <span style="color: #339933; font-weight: bold;">*</span> <span style="color: red;">2</span><span style="color: green;">&#41;</span>
quad <span style="color: #339933; font-weight: bold;">=</span> Func <span style="background-color: #3cb371;">&quot;quad&quot;</span> <span style="color: green;">&#40;</span>Call <span style="background-color: #3cb371;">&quot;double&quot;</span> <span style="color: green;">&#40;</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">*</span>Param<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span></pre></div></div>

<p>This example outputs:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;">double<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">ebp</span>
	<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ebp</span><span style="color: #339933;">,</span><span style="color: #00007f;">esp</span>
	<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">8</span><span style="color: #009900; font-weight: bold;">&#93;</span>
	<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">2</span>
	<span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">ebx</span>
	<span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">eax</span>
	<span style="color: #00007f; font-weight: bold;">imul</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #00007f;">ebx</span>
	<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
	<span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">eax</span>
	<span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">ebp</span>
	<span style="color: #00007f; font-weight: bold;">ret</span> <span style="color: #0000ff;">4</span>
&nbsp;
quad<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">ebp</span>
	<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ebp</span><span style="color: #339933;">,</span><span style="color: #00007f;">esp</span>
	<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">2</span>
	<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">8</span><span style="color: #009900; font-weight: bold;">&#93;</span>
	<span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">ebx</span>
	<span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">eax</span>
	<span style="color: #00007f; font-weight: bold;">imul</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #00007f;">ebx</span>
	<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
	<span style="color: #00007f; font-weight: bold;">call</span> double
	<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span>
	<span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">eax</span>
	<span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">ebp</span>
	<span style="color: #00007f; font-weight: bold;">ret</span> <span style="color: #0000ff;">4</span></pre></div></div>

<p>Not the most efficient code in the world <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_wink.gif" alt="" /> The calling convention is somewhat ad-hoc; the callee must remove its arguments from the stack and returns its value in <code>eax</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/generating-x86-assembly-with-haskell/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
