<?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:media="http://search.yahoo.com/mrss"
	>

<channel>
	<title>The Wandering Glitch</title>
	<atom:link href="http://aabs.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://aabs.wordpress.com</link>
	<description>Closed weekends and holidays.</description>
	<pubDate>Mon, 05 May 2008 11:27:30 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
			<item>
		<title>Søren on DBC</title>
		<link>http://aabs.wordpress.com/2008/05/05/s%c3%b8ren-on-dbc/</link>
		<comments>http://aabs.wordpress.com/2008/05/05/s%c3%b8ren-on-dbc/#comments</comments>
		<pubDate>Mon, 05 May 2008 11:27:30 +0000</pubDate>
		<dc:creator>Andrew Matthews</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Readify]]></category>

		<category><![CDATA[functional programming]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[DBC]]></category>

		<guid isPermaLink="false">http://aabs.wordpress.com/?p=529</guid>
		<description><![CDATA[Recently, Søren Skovsbøll wrote a excellent follow up to a little post I did a while back on using C# 3.0 expression trees for representing predicates in design by contract. The conclusion of that series was that C# was inadequate in lots of ways to the task of doing design by contract. Having said that, you [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recently, <a href="http://skarpt.dk/blog">Søren Skovsbøll</a> wrote a excellent follow up to a little post I did a while back on using <a href="http://aabs.wordpress.com/2008/01/16/complex-assertions-using-c-30/">C# 3.0 expression trees</a> for representing predicates in design by contract. The conclusion of that series was that C# was inadequate in lots of ways to the task of doing design by contract. Having said that, you can still achieve a lot using serialisation of object states and storage of predicates for running before and after a scope.</p>
<p>Søren was not happy with the format of errors being reported, nor the potential for massive serialisation blowout. Rather than comment on the blog, he went away and did something about it. And it&#8217;s pretty good! Go <a href="http://skarpt.dk/blog/?p=14">take a look</a>, and then pick up the baton from him. Your challenge is to extract the parmeter objects from the expression trees of the predicates and take lightweight snapshots of the objects refered to. You also need a &#8220;platform independent&#8221; way to serialize objects for this scheme (i.e. one that doesn&#8217;t depend on XmlSerialisation or WCF data contracts.</p>
<p>Think you can do it? Apply here! :P</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aabs.wordpress.com/529/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aabs.wordpress.com/529/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aabs.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aabs.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aabs.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aabs.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aabs.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aabs.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aabs.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aabs.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aabs.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aabs.wordpress.com/529/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aabs.wordpress.com&blog=155386&post=529&subd=aabs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aabs.wordpress.com/2008/05/05/s%c3%b8ren-on-dbc/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/aabs-128.jpg" medium="image">
			<media:title type="html">AABS</media:title>
		</media:content>
	</item>
		<item>
		<title>Announcing LinqToRdf v0.6</title>
		<link>http://aabs.wordpress.com/2008/05/04/announcing-linqtordf-v06/</link>
		<comments>http://aabs.wordpress.com/2008/05/04/announcing-linqtordf-v06/#comments</comments>
		<pubDate>Sun, 04 May 2008 12:54:24 +0000</pubDate>
		<dc:creator>Andrew Matthews</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Readify]]></category>

		<category><![CDATA[Semantic Web]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[LinqToRdf]]></category>

		<guid isPermaLink="false">http://aabs.wordpress.com/?p=520</guid>
		<description><![CDATA[I&#8217;ve just uploaded LinqToRdf v0.6 with improved designer support for Visual Studio .NET 2008.
The release includes the following high-points:

LinqToRdf Designer and VS.NET 2008 extension completely rewritten  
LinqToRdf Installer now includes the installer of LinqToRdf Designer (at no extra cost)  
Project and Item templates now installed as part of LinqToRdf Designer  
Generated object [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve just uploaded LinqToRdf v0.6 with improved designer support for Visual Studio .NET 2008.</p>
<p>The release includes the following high-points:</p>
<ul>
<li>LinqToRdf Designer and VS.NET 2008 extension completely rewritten  </li>
<li>LinqToRdf Installer now includes the installer of LinqToRdf Designer (at no extra cost)  </li>
<li>Project and Item templates now installed as part of LinqToRdf Designer  </li>
<li>Generated object and data properties now get their own EntitySet or EntityRef.  </li>
<li>Generates LINQ to SQL-style DataContext objects to hide query creation. Much Cleaner. </li>
</ul>
<p>The user experience for LinqToRdf should be greatly improved in this release.&nbsp; I focussed on getting project and item templates set up that would allow you to either create a dedicated LinqToRdf project that would have all the assembly references set up for you, or to create a new LinqToRdf designer file, that would generate C# code based on the new Attribute model introduced a few versions back.</p>
<p>The VS.NET extensions are not installed by default, instead they are created in the LinqToRdf directory. If you do install them, then you will find that visual studio will now have a LinqToRdf will have a new project type.</p>
<p><a href="http://aabs.files.wordpress.com/2008/05/clip-image0015.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="274" alt="clip_image001[5]" src="http://aabs.files.wordpress.com/2008/05/clip-image0015-thumb.png?w=614&h=274" width="614"/></a> </p>
<p>You also have the LinqToRdf designer file type, which has been around for a version or two: </p>
<p><a href="http://aabs.files.wordpress.com/2008/05/image.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="299" alt="image" src="http://aabs.files.wordpress.com/2008/05/image-thumb.png?w=540&h=299" width="540"/></a>  </p>
<p>The Solution view is like this: </p>
<p><a href="http://aabs.files.wordpress.com/2008/05/clip-image0017.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="180" alt="clip_image001[7]" src="http://aabs.files.wordpress.com/2008/05/clip-image0017-thumb.png?w=236&h=180" width="236"/></a> </p>
<p>The designer view is the same as ever: </p>
<p><a href="http://aabs.files.wordpress.com/2008/05/clip-image0019.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="457" alt="clip_image001[9]" src="http://aabs.files.wordpress.com/2008/05/clip-image0019-thumb.png?w=576&h=457" width="576"/></a> </p>
<p>Things are coming along, and the download stats for version 0.4 were actually quite healthy (at least i think they were) so I expect this version to be the most popular yet. </p>
<p>Expect to see the lazy-loading relationship representation process fully documented in the coming days.</p>
<p>Enjoy.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aabs.wordpress.com/520/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aabs.wordpress.com/520/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aabs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aabs.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aabs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aabs.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aabs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aabs.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aabs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aabs.wordpress.com/520/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aabs.wordpress.com/520/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aabs.wordpress.com/520/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aabs.wordpress.com&blog=155386&post=520&subd=aabs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aabs.wordpress.com/2008/05/04/announcing-linqtordf-v06/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/aabs-128.jpg" medium="image">
			<media:title type="html">AABS</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/05/clip-image0015-thumb.png" medium="image">
			<media:title type="html">clip_image001[5]</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/05/image-thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/05/clip-image0017-thumb.png" medium="image">
			<media:title type="html">clip_image001[7]</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/05/clip-image0019-thumb.png" medium="image">
			<media:title type="html">clip_image001[9]</media:title>
		</media:content>
	</item>
		<item>
		<title>Announcing LinqToRdf v0.5</title>
		<link>http://aabs.wordpress.com/2008/04/26/announcing-linqtordf-v05/</link>
		<comments>http://aabs.wordpress.com/2008/04/26/announcing-linqtordf-v05/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 09:31:36 +0000</pubDate>
		<dc:creator>Andrew Matthews</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Semantic Web]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://aabs.wordpress.com/2008/04/26/announcing-linqtordf-v05/</guid>
		<description><![CDATA[The fifth release of LinqToRdf has just been uploaded to Google Code.  
Go to http://code.google.com/p/linqtordf for links to the latest MSI installer.  
LinqToRdf Changes: - Member access projections like this: &#160; from a in c select a.Name - initial support for Distinct results - latest versions of SemWeb &#38; SPARQL Engine, incorporating the [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a name="msg_06050fdd438f8b01"></a>The fifth release of LinqToRdf has just been uploaded to Google Code.  </p>
<p>Go to <a href="http://code.google.com/p/linqtordf">http://code.google.com/p/linqtordf</a> for links to the latest MSI <br />installer.  </p>
<p>LinqToRdf Changes: <br />- Member access projections like this: <br />&nbsp; from a in c select a.Name <br />- initial support for Distinct results <br />- latest versions of SemWeb &amp; SPARQL Engine, incorporating the new <br />SqlServer store provider <br />- updated the DSL tools to compile on RTM version of VS.NET 2008  </p>
<p>Please let me know how you get on. </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aabs.wordpress.com/519/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aabs.wordpress.com/519/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aabs.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aabs.wordpress.com/519/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aabs.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aabs.wordpress.com/519/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aabs.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aabs.wordpress.com/519/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aabs.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aabs.wordpress.com/519/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aabs.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aabs.wordpress.com/519/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aabs.wordpress.com&blog=155386&post=519&subd=aabs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aabs.wordpress.com/2008/04/26/announcing-linqtordf-v05/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/aabs-128.jpg" medium="image">
			<media:title type="html">AABS</media:title>
		</media:content>
	</item>
		<item>
		<title>SPARQL Tutorial Just Published On DeveloperWorks</title>
		<link>http://aabs.wordpress.com/2008/04/23/sparql-tutorial-just-published-on-developerworks/</link>
		<comments>http://aabs.wordpress.com/2008/04/23/sparql-tutorial-just-published-on-developerworks/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 10:22:35 +0000</pubDate>
		<dc:creator>Andrew Matthews</dc:creator>
		
		<category><![CDATA[Semantic Web]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://aabs.wordpress.com/?p=518</guid>
		<description><![CDATA[
The Semantic Web, a knowledge-centric model for the Web&#8217;s future, supplements human-readable documents and XML message formats with data that can be understood and processed by machines. SPARQL Protocol and RDF Query Language (SPARQL) is to the semantic Web as SQL is to a relational database. It allows applications to make sophisticated queries against distributed [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://www.ibm.com/developerworks/edu/x-dw-x-sparql.html?S_TACT=105AGX01&amp;S_CMP=HP"><img src="http://aabs.files.wordpress.com/2008/04/clip-image0016.png?w=599&h=174" alt="clip_image001[6]" width="599" height="174" /></a></p>
<p>The Semantic Web, a knowledge-centric model for the Web&#8217;s future, supplements human-readable documents and XML message formats with data that can be understood and processed by machines. SPARQL Protocol and RDF Query Language (SPARQL) is to the semantic Web as SQL is to a relational database. It allows applications to make sophisticated queries against distributed RDF databases, and is widely supported by many competing frameworks. This tutorial demonstrates its use through the example of a team tracking and journaling system for a virtual company.</p>
<p>(by Yours Truly :)</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aabs.wordpress.com/518/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aabs.wordpress.com/518/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aabs.wordpress.com/518/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aabs.wordpress.com/518/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aabs.wordpress.com/518/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aabs.wordpress.com/518/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aabs.wordpress.com/518/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aabs.wordpress.com/518/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aabs.wordpress.com/518/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aabs.wordpress.com/518/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aabs.wordpress.com/518/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aabs.wordpress.com/518/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aabs.wordpress.com&blog=155386&post=518&subd=aabs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aabs.wordpress.com/2008/04/23/sparql-tutorial-just-published-on-developerworks/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/aabs-128.jpg" medium="image">
			<media:title type="html">AABS</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/04/clip-image0016.png" medium="image">
			<media:title type="html">clip_image001[6]</media:title>
		</media:content>
	</item>
		<item>
		<title>Functional Programming in C# - Higher-Order Functions</title>
		<link>http://aabs.wordpress.com/2008/04/16/functional-programming-in-csharp-higher-order-functions/</link>
		<comments>http://aabs.wordpress.com/2008/04/16/functional-programming-in-csharp-higher-order-functions/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 10:58:06 +0000</pubDate>
		<dc:creator>Andrew Matthews</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[Readify]]></category>

		<category><![CDATA[functional programming]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[.NET 3.5]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://aabs.wordpress.com/?p=516</guid>
		<description><![CDATA[This is the second in a series on the basics of functional programming using C#. My topic today is one I touched on last time, when I described the rights and privileges of a function as a first class citizen. I'm going to explore Higher-Order Functions this time. Higher-Order Functions are functions that themselves take or return functions. Meta-functions, if you like.]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><ol>
<li><a title="Functional Programming - Is it worth your time?" href="http://aabs.wordpress.com/2008/04/09/functional-programming-is-it-worth-your-time/">Functional Programming - Is it worth your time?</a></li>
<li><a href="http://aabs.wordpress.com/2008/04/16/unctional-programming-in-csharp-higher-order-functions/">Functional Programming in C# - Higher-Order Functions</a></li>
</ol>
<p>This is the second in a series on the basics of functional programming using C#. My topic today is one I touched on last time, when I described the rights and privileges of a function as a first class citizen. I&#8217;m going to explore Higher-Order Functions this time. Higher-Order Functions are functions that themselves take or return functions. Meta-functions, if you like.</p>
<p>As I explained last time, my programming heritage is firmly in the object-oriented camp. For me, the construction, composition and manipulation of composite data structures is second nature. A higher-order function is the equivalent from the functional paradigm. You can compose, order and recurse a tree of functions in just the same way as you manipulate your data. I&#8217;m going to describe a few of the techniques for doing that using an example of pretty printing some source code for display on a web site.</p>
<p>I&#8217;ve just finished a little project at <a href="http://www.readify.net">Readify </a>allowing us to conduct code reviews whenever an interesting code change gets checked into our TFS servers. A key feature of that is pretty-printing the source before rendering it. Obviously, if you&#8217;re displaying XHTML on an XHTML page, your browser will get confused pretty quickly unless you take steps to HTML-escape all the XHTML entities that might corrupt the display. The examples I&#8217;ll show will highlight the difference between the procedural and functional approaches.</p>
<p>This example shows a fairly typical implementation that takes a file that&#8217;s been split into lines:</p>
<p><span style="color:#0000ff;">public static string</span>[] RenderLinesProcedural(<span style="color:#0000ff;">string</span>[] lines)<br />
{<br />
    <span style="color:#0000ff;">for </span>(<span style="color:#0000ff;">int </span>i = 0; i &lt; lines.Count(); i++)<br />
    {<br />
      lines[i] = EscapeLine(lines[i]);<br />
    }<br />
    <span style="color:#0000ff;">return </span>lines;<br />
}</p>
<p><span style="color:#0000ff;">public static string </span>EscapeLine(<span style="color:#0000ff;">string </span>line)<br />
{<br />
  <span style="color:#2b91af;">Debug</span>.WriteLine(<span style="color:#a31515;">&#8220;converting &#8221; </span>+ line);<br />
  <span style="color:#0000ff;">return </span>line.Replace(<span style="color:#a31515;">&#8221; &#8220;</span>, <span style="color:#a31515;">&#8220;  &#8221;</span>)<br />
      .Replace(<span style="color:#a31515;">&#8220;\t&#8221;</span>, <span style="color:#a31515;">&#8220;  &#8221;</span>)<br />
      .Replace(<span style="color:#a31515;">&#8220;&lt;&#8221;</span>, <span style="color:#a31515;">&#8220;&lt;&#8221;</span>)<br />
      .Replace(<span style="color:#a31515;">&#8220;&gt;&#8221;</span>, <span style="color:#a31515;">&#8220;&gt;&#8221;</span>);<br />
}</p>
<p>There&#8217;s a few things worth noticing here. In C#, strings are immutable. That means that whenever you think that you are changing a string, you&#8217;re not. In the background, the CLR is constructing a modified copy of the string for you. The Array of strings on the other hand is not immutable, therefore a legitimate procedural approach is to make an in-place modification of the original collection and pass that back.  The EscapeLine method repeatedly makes modified copies of the line string passing back the last copy.</p>
<p>Despite C# not being a pure functional programming language[<a href="http://en.wikipedia.org/wiki/Functional_programming#Pure_functions">1</a>], it&#8217;s still doing a lot of copying in this little example. My early impression was that pure functional programming (where all values are immutable) would be inefficient because of all the copying goign on. Yet here is a common-or-garden object oriented language that uses exactly the same approach to managing data, and we all use it without a qualm. In case you didn&#8217;t know, StringBuilder is what you should be using if you need to make in-place modifications to strings.</p>
<p>Let&#8217;s run the procedural code and record what happens:</p>
<p><span style="color:#0000ff;">private static void </span>TestProcedural()<br />
{<br />
   <span style="color:#0000ff;">string</span>[] originalLines = <span style="color:#0000ff;">new string</span>[] { <span style="color:#a31515;">&#8220;&lt;head&gt;&#8221;</span>, <span style="color:#a31515;">&#8220;&lt;/head&gt;&#8221; </span>};<br />
   <span style="color:#2b91af;">Debug</span>.WriteLine(<span style="color:#a31515;">&#8220;Converting the lines&#8221;</span>);<br />
   <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#0000ff;">string</span>&gt; convertedStrings = RenderLinesProcedural(originalLines);<br />
   <span style="color:#2b91af;">Debug</span>.WriteLine(<span style="color:#a31515;">&#8220;Converted the lines?&#8221;</span>);</p>
<p><span style="color:#0000ff;">   foreach </span>(<span style="color:#0000ff;">string </span>s <span style="color:#0000ff;">in </span>convertedStrings)<br />
    {<br />
    <span style="color:#2b91af;">Debug</span>.WriteLine(s);<br />
    }<br />
}</p>
<p>Here&#8217;s the output:</p>
<blockquote><p><a href="http://aabs.files.wordpress.com/2008/04/clip-image001.png"><img style="border-width:0;" src="http://aabs.files.wordpress.com/2008/04/clip-image001-thumb.png?w=165&h=118" alt="clip_image001" width="165" height="118" /></a></p></blockquote>
<p>As you can see, the lines all got converted before we even got to the &#8220;converted the lines?&#8221; statement. That&#8217;s called &#8216;Eager Evaluation&#8217;, and it certainly has its place in some applications. Now lets use Higher-Order Functions:</p>
<p><span style="color:#0000ff;">public static </span><span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#0000ff;">string</span>&gt; RenderLinesFunctional(<span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#0000ff;">string</span>&gt; lines)<br />
{<br />
    <span style="color:#0000ff;">return </span>lines.Map(s =&gt; EscapeString(s));<br />
}</p>
<p><span style="color:#0000ff;">static </span><span style="color:#2b91af;">IEnumerable</span>&lt;R&gt; Map&lt;T, R&gt;(<span style="color:#0000ff;">this </span><span style="color:#2b91af;">IEnumerable</span>&lt;T&gt; seq, <span style="color:#2b91af;">Func</span>&lt;T, R&gt; f)<br />
{<br />
   <span style="color:#0000ff;">foreach </span>(<span style="color:#0000ff;">var </span>t <span style="color:#0000ff;">in </span>seq)<br />
     <span style="color:#0000ff;">yield return </span>f(t);<br />
}</p>
<p><span style="color:#0000ff;"><span>static string </span></span>EscapeString(<span style="color:#0000ff;">string </span>s)<br />
{<br />
   <span style="color:#2b91af;">Debug</span>.WriteLine(<span style="color:#a31515;">&#8220;converting &#8221; </span>+ s);<br />
   <span style="color:#0000ff;">return </span>s.Replace(<span style="color:#a31515;">&#8220;  &#8220;</span>, <span style="color:#a31515;">&#8220;&amp;nbsp;&amp;nbsp;&#8221;</span>)<br />
     .Replace(<span style="color:#a31515;">&#8220;\t&#8221;</span>, <span style="color:#a31515;">&#8220;&amp;nbsp;&amp;nbsp;&#8221;</span>)<br />
     .Replace(<span style="color:#a31515;">&#8220;&lt;&#8221;</span>, <span style="color:#a31515;">&#8220;&amp;lt;&#8221;</span>)<br />
     .Replace(<span style="color:#a31515;">&#8220;&gt;&#8221;</span>, <span style="color:#a31515;">&#8220;&amp;gt;&#8221;</span>);<br />
}</p>
<p><span style="color:#0000ff;">private static void </span>TestFunctional()<br />
{<br />
   <span style="color:#0000ff;">string</span>[] originalLines = <span style="color:#0000ff;">new string</span>[] { <span style="color:#a31515;">&#8220;&lt;head&gt;&#8221;</span>, <span style="color:#a31515;">&#8220;&lt;/head&gt;&#8221; </span>};<br />
   <span style="color:#2b91af;">Debug</span>.WriteLine(<span style="color:#a31515;">&#8220;Converting the lines&#8221;</span>);<br />
   <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#0000ff;">string</span>&gt; convertedStrings = RenderLinesFunctional(originalLines);<br />
   <span style="color:#2b91af;">Debug</span>.WriteLine(<span style="color:#a31515;">&#8220;Converted the lines?&#8221;</span>);</p>
<p><span style="color:#0000ff;">   foreach </span>(<span style="color:#0000ff;">string </span>s <span style="color:#0000ff;">in </span>convertedStrings)<br />
    {<br />
    <span style="color:#2b91af;">Debug</span>.WriteLine(s);<br />
    }<br />
}</p>
<p>This time the output looks different:</p>
<blockquote><p><a href="http://aabs.files.wordpress.com/2008/04/clip-image0015.png"><img style="border-width:0;" src="http://aabs.files.wordpress.com/2008/04/clip-image0015-thumb.png?w=157&h=113" alt="clip_image001[5]" width="157" height="113" /></a></p></blockquote>
<p>At the time that the &#8220;Converted the Lines?&#8221; statement gets run, the lines have not yet been converted. This is called &#8216;Lazy Evaluation[<a href="http://en.wikipedia.org/wiki/Lazy_evaluation">2</a>]&#8216;, and it&#8217;s a powerful weapon in the functional armamentarium. For the simple array that I&#8217;m showing here, the technique looks like overkill but imagine that you were using a paged control on a big TFS installation like Readify&#8217;s <a href="http://www.tfsnow.com/Tour/WhatIsTFS.aspx">TFSNow</a>. You might have countless code reviews going on. If you rendered every line of code in all the files being viewed, you would waste both processor and bandwidth resources needlessly.</p>
<p>So what did I do to change the way this program worked so fundamentally? Well the main thing was to opt to use the IEnumerable interface, which then gave me the scope to provide an alternative implementation to representing the collection. in the procedural example, the return type was a string array, so I was bound to create and populate the array before returning from the function. That&#8217;s a point worth highlighting: <strong><em>Use iterators as return types where possible - they allow you to mix <a href="http://en.wikipedia.org/wiki/Programming_paradigms">paradigms</a></em></strong>. Converting to IEnumerables is not enough. I could change the signature of TestProcedural to use iterators, but it would still have used Eager Evaluation.</p>
<p>The next thing I did was use the Map function to return a functional iterator rather than a concrete object graph as was done in the procedural example. I created Map here to demonstrate that there was no funny LINQ business going on in the background. In most cases I would use the <span style="font-size:x-small;font-family:Courier New;">Enumerable.Select()</span> extension method from LINQ to do the same thing. Map is a function that is common in functional programming, it allows the lazy transformation of a stream or collection into something more useful. Map is the crux of the transformation - it allows you to insert a function into the simple process of iterating a collection.</p>
<p>Map is a Higher-Order Function, it accepts a function as a parameter and applies it to a collection on demand. Eventually you will need to deal with raw data - such as when you bind it to a GridView. Till that point you can hold off on committing resources that may not get used. Map is not the only HOF that we can use in this scenario. We&#8217;re repeatedly calling String.Replace in our functions. Perhaps we can generalise the idea of repeatedly calling a function with different parameters.</p>
<p><span style="color:#2b91af;">Func</span>&lt;T, T&gt; On&lt;T&gt;(<span style="color:#0000ff;">this </span><span style="color:#2b91af;">Func</span>&lt;T, T&gt; f, <span style="color:#2b91af;">Func</span>&lt;T, T&gt; g)<br />
{<br />
    <span style="color:#0000ff;">return </span>t =&gt; g(f(t));<br />
}</p>
<p>This method encapsulates the idea of composing functions. I&#8217;m creating a function that returns the result of applying the inner function to an input value of type T, and then applying the outer function to the result. In normal mathematical notation this would be represented by the notation &#8220;g <span style="font-size:xx-small;">o</span> f&#8221;, meaning <em>g </em>applied to <em>f</em>. Composition is a key way of building up more complex functions. It&#8217;s the linked list of the functional world - well it would be if the functional world were denied normal data structures, which it isn&#8217;t. :P</p>
<p>Notice that I&#8217;m using an extension method here, to make it nicer to deal with functions in your code. The next example is just a test method to introduce the new technique.</p>
<p><span style="color:#0000ff;">private static void </span>TestComposition()<br />
{<br />
    <span style="color:#0000ff;">var </span>seq1 = <span style="color:#0000ff;">new int</span>[] { 1, 3, 5, 7, 11, 13, 19 };<br />
    <span style="color:#0000ff;">var </span>g = ((<span style="color:#2b91af;">Func</span>&lt;<span style="color:#0000ff;">int</span>, <span style="color:#0000ff;">int</span>&gt;)(a =&gt; a + 2)).On(b =&gt; b * b).On(c =&gt; c + 1);<br />
    <span style="color:#0000ff;">foreach </span>(<span style="color:#0000ff;">var </span>i <span style="color:#0000ff;">in </span>seq1.Map(g))<br />
    {<br />
      <span style="color:#2b91af;">Debug</span>.WriteLine(i);<br />
    }<br />
}</p>
<p>TestComposition uses the &#8216;On&#8217; extension to compose functions into more complex functions. The actual function is not really that important, the point is that I packaged up a group of functions to be applied in order to an input value and then stored that function for later use. You might think that that&#8217;s no big deal, since the function could be achieved by even the most trivial procedure. But this is dynamically composing functions - think about what you could do with dynamically composable functions that don&#8217;t require complex control logic to make them work properly. Our next example shows how this can be applied to escaping strings for display on a web page.</p>
<p><span style="color:#0000ff;">void </span>TestComposition2()<br />
{<br />
   <span style="color:#0000ff;">var </span>strTest = <span style="color:#a31515;">@&#8221;&lt;html&gt;&lt;body&gt;hello world&lt;/body&gt;&lt;/html&gt;&#8221;</span>;<br />
   <span style="color:#0000ff;">string</span>[][] replacements = <span style="color:#0000ff;">new</span>[]<br />
     {<br />
       <span style="color:#0000ff;">new</span>[]{<span style="color:#a31515;">&#8220;&amp;&#8221;</span>, <span style="color:#a31515;">&#8220;&amp;amp;&#8221;</span>},<br />
       <span style="color:#0000ff;">new</span>[]{<span style="color:#a31515;">&#8220;  &#8220;</span>, <span style="color:#a31515;">&#8220;&amp;nbsp;&amp;nbsp;&#8221;</span>},<br />
       <span style="color:#0000ff;">new</span>[]{<span style="color:#a31515;">&#8220;\t&#8221;</span>, <span style="color:#a31515;">&#8220;&amp;nbsp;&amp;nbsp;&#8221;</span>},<br />
       <span style="color:#0000ff;">new</span>[]{<span style="color:#a31515;">&#8220;&lt;&#8221;</span>, <span style="color:#a31515;">&#8220;&amp;lt;&#8221;</span>},<br />
       <span style="color:#0000ff;">new</span>[]{<span style="color:#a31515;">&#8220;&gt;&#8221;</span>, <span style="color:#a31515;">&#8220;&amp;gt;&#8221;</span>}<br />
     };</p>
<p><span style="color:#2b91af;">  Func</span>&lt;<span style="color:#0000ff;">string</span>, <span style="color:#0000ff;">string</span>&gt; f = x =&gt; x;<br />
  <span style="color:#0000ff;">foreach </span>(<span style="color:#0000ff;">string</span>[] strings <span style="color:#0000ff;">in </span>replacements)<br />
  {<br />
     <span style="color:#0000ff;">var </span>s0 = strings[0];<br />
     <span style="color:#0000ff;">var </span>s1 = strings[1];<br />
     f = f.On(s =&gt; s.Replace(s0, s1));<br />
  }</p>
<p><span style="color:#2b91af;">  Debug</span>.WriteLine(f(strTest));<br />
}</p>
<p>This procedure is again doing something quite significant - it&#8217;s taking a data structure and using that to guide the construction of a function that performs some data-driven processing on other data. Imagine that you took this from config data or a database somewhere. The function that gets composed is a fast, directly executable, encapsulated, interface free, type safe, dynamically generated unit of functionality. It has many of the benefits of the Gang Of Four Strategy Pattern[<a href="http://en.wikipedia.org/wiki/Strategy_pattern">3</a>].</p>
<p>The techniques I&#8217;ve shown in this post demonstrate some of the power of the functional paradigm. I described how you can combine higher order functions with iterators to give a form of lazy evaluation. I also showed how you can compose functions to build up fast customised functions that can be data-driven. I&#8217;ve also shown a simple implementation of the common Map method that allows a function to be applied to each of the elements of a collection. Lastly I provided a generic implementation of a function composition mechanism that allows you to build up complex functions within a domain.</p>
<p>Next time I&#8217;ll introduce the concept of closure, which we&#8217;ve seen here at work in the &#8216;On&#8217; composition function.</p>
<p>Some references:</p>
<p>1. Wikipedia: <a title="http://en.wikipedia.org/wiki/Functional_programming#Pure_functions" href="http://en.wikipedia.org/wiki/Functional_programming#Pure_functions">Pure Functions</a></p>
<p>2. Wikipedia: <a title="Lazy evaluation" href="http://en.wikipedia.org/wiki/Lazy_evaluation">Lazy Evaluation</a></p>
<p>3. Wikipedia: <a title="http://en.wikipedia.org/wiki/Strategy_pattern" href="http://en.wikipedia.org/wiki/Strategy_pattern">Strategy Pattern</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aabs.wordpress.com/516/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aabs.wordpress.com/516/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aabs.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aabs.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aabs.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aabs.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aabs.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aabs.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aabs.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aabs.wordpress.com/516/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aabs.wordpress.com/516/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aabs.wordpress.com/516/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aabs.wordpress.com&blog=155386&post=516&subd=aabs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aabs.wordpress.com/2008/04/16/functional-programming-in-csharp-higher-order-functions/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/aabs-128.jpg" medium="image">
			<media:title type="html">AABS</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/04/clip-image001-thumb.png" medium="image">
			<media:title type="html">clip_image001</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/04/clip-image0015-thumb.png" medium="image">
			<media:title type="html">clip_image001[5]</media:title>
		</media:content>
	</item>
		<item>
		<title>Darth Vader never had to put up with this!</title>
		<link>http://aabs.wordpress.com/2008/04/10/darth-vader-never-had-to-put-up-with-this/</link>
		<comments>http://aabs.wordpress.com/2008/04/10/darth-vader-never-had-to-put-up-with-this/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 02:14:55 +0000</pubDate>
		<dc:creator>Andrew Matthews</dc:creator>
		
		<category><![CDATA[106454]]></category>

		<guid isPermaLink="false">http://aabs.wordpress.com/2008/04/10/darth-vader-never-had-to-put-up-with-this/</guid>
		<description><![CDATA[I never once saw Luke Skywalker having a tantrum when his daddy was too busy working on the Death Star to stop and fix Luke&#8217;s Light Saber.

       ]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I never once saw Luke Skywalker having a tantrum when his daddy was too busy working on the Death Star to stop and fix Luke&#8217;s Light Saber.</p>
<p><a href="http://aabs.files.wordpress.com/2008/04/img-0595.jpg"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="389" alt="IMG_0595" src="http://aabs.files.wordpress.com/2008/04/img-0595-thumb.jpg?w=517&h=389" width="517"/></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aabs.wordpress.com/509/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aabs.wordpress.com/509/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aabs.wordpress.com/509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aabs.wordpress.com/509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aabs.wordpress.com/509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aabs.wordpress.com/509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aabs.wordpress.com/509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aabs.wordpress.com/509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aabs.wordpress.com/509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aabs.wordpress.com/509/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aabs.wordpress.com/509/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aabs.wordpress.com/509/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aabs.wordpress.com&blog=155386&post=509&subd=aabs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aabs.wordpress.com/2008/04/10/darth-vader-never-had-to-put-up-with-this/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/aabs-128.jpg" medium="image">
			<media:title type="html">AABS</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/04/img-0595-thumb.jpg" medium="image">
			<media:title type="html">IMG_0595</media:title>
		</media:content>
	</item>
		<item>
		<title>Functional programming - Is it worth your time?</title>
		<link>http://aabs.wordpress.com/2008/04/09/functional-programming-is-it-worth-your-time/</link>
		<comments>http://aabs.wordpress.com/2008/04/09/functional-programming-is-it-worth-your-time/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 12:18:29 +0000</pubDate>
		<dc:creator>Andrew Matthews</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[106454]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[.NET 3.5]]></category>

		<category><![CDATA[C#]]></category>

		<category><![CDATA[C# 3.0]]></category>

		<category><![CDATA[functional programming]]></category>

		<guid isPermaLink="false">http://aabs.wordpress.com/?p=508</guid>
		<description><![CDATA[Functional Programming is probably simpler than you think. It's based on the idea that there is often very little distinction between programs an data. This post explores the basic techniques of functional programming and demonstrates their use in C#.]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Short Answer: Yes!</p>
<p>Regular readers of the The Wandering Glitch know I focused lots of attention on LINQ and the new wave of language innovation in C# 3.0. I&#8217;m intrigued by functional programming in C#. At university, I focused on languages like C, C++, Eiffel and Ada. I&#8217;ve never since needed to learn functional programming techniques - who uses them, after all? Functional programming had always seemed like a distant offshoot of some<span>  </span><a href="http://en.wikipedia.org/wiki/Nicolas_Bourbaki#cite_note-0">Bourbakiste</a> school of mathematical programming unconcerned with practical issues of software development. Don&#8217;t get me wrong - I find that attractive, but it was always hard to justify the time, when there was so much else of practical worth that I needed to study. So the years passed, and I never came near. Functional programming was suffering from bad PR. But times change.</p>
<p style="font-size:11pt;font-family:Calibri;margin:0;">A fundamental change is under way in how we develop software. Declarative, Functional, Model-driven, Aspect-oriented and Logic Programming are all examples where new ways of representing and solving problems<span> can </span>pay huge dividends in programmer productivity and system maintainability.<span>  </span>Suddenly, it no longer seems that functional programming is a means to try out obscure new forms of lambda calculus. Now it seems that there are fast, powerful, easy to understand techniques to be learnt that will make my systems more robust and smaller.</p>
<p style="font-size:11pt;font-family:Calibri;margin:0;"> </p>
<p style="font-size:11pt;font-family:Calibri;margin:0;">I regretted not learning functional programming - I felt that there were ideas I was missing out on. And that made me envious. So, now is as good a time as any to address that deficiency. Another deficiency I want to address is the dearth of posts on the Glitch. I got tied up in producing a SPARQL tutorial for IBM which swallowed up my evenings. After that I had in mind to pursue an idea for a blog post on the relationships between LINQ, and Meta-mathematical structures like Groups and Categories. I got a major dose of intellectual indigestion, which stopped me from producing anything. The only way I&#8217;ll get productive again is to break the topics I want to cover into bite-sized chunks. that&#8217;s enough apologia - here&#8217;s the post.</p>
<p><a href="http://en.wikipedia.org/wiki/Functional_programming">Functional Programming</a> is probably simpler than you think. It&#8217;s based on the idea that there is often very little distinction between programs an data. Consider this function &#8216;f&#8217;: </p>
<p><code>f(x): x + 5</code></p>
<p>This function &#8216;f&#8217; adds five to whatever you pass into f. What do I mean when I say &#8216;f&#8217;. I&#8217;m talking about the function, not using it. It came completely naturally for you to go along with me and describe the function &#8216;f&#8217; as a thing. Here&#8217;s what I mean:</p>
<p><code>  g(f, x): f(x) + 7</code></p>
<p>This function &#8216;g&#8217; adds 7 to the result of calling &#8216;f&#8217; on x. So the final result would be &#8216;(x + 5 ) + 7&#8242;. You see, that wasn&#8217;t really a complex concept at all. Yet that&#8217;s the essence of functional programming. To put it another way:</p>
<blockquote><p><em>Functions are first class citizens.</em></p></blockquote>
<p>Which means that:</p>
<ul>
<li>They can be named by variables.</li>
<li>They can be passed as arguments to procedures.</li>
<li>They can be returned as values of procedures.</li>
<li>They can be incorporated into data structures. [<a href="http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&amp;tid=3305">1</a>]</li>
</ul>
<p>It should also mean that you can compose your own functions as I did with &#8216;f&#8217; and &#8216;g&#8217; earlier. Another possibly less vital feature to empower this charter for the rights and privileges of functions is the &#8216;lambda&#8217; (or λ) function. A lambda function is simply a way to create function on the fly, without having to give it a name. Compare this C# function:</p>
<p><code>int f(int x){return x + 5;}</code></p>
<p>With this one:</p>
<p><code>int f(int x)<br />
{<br />
  int c = 5;<br />
  return x + c;<br />
}</code></p>
<p>They both perform the same function, but the second one pointlessly created a name for the value &#8216;5&#8242;. The first example got by perfectly well without having to give a name to the value it was working with. Well, the same principle applies to lambda functions. Here&#8217;s a C# example that does what &#8216;g&#8217; did above:</p>
<p><code>int g(Func&lt;int , int&gt; f, int x){return f(x) + 7;}</code></p>
<p>The &#8216;Func&lt;int, int&gt; f&#8217; syntax is a new piece of C#, used to represent that f is a function that takes a single int and returns an int. you can probably already see that this function &#8216;g&#8217; could be used with many different functions, but sometimes we don&#8217;t want to exercise our right to be able to name those functions with variables. To just create a function, without naming it (to use an &#8216;anonymous function&#8217; in .NET parlance) you use the new lambda function syntax in C# 3.0:</p>
<p><code>int x = 3;<br />
int z = g(y =&gt; y + 5, x);</code></p>
<p>&#8216;g&#8217; gets an anonymous function and an integer as parameter, runs the function with the parameter, adds 7 to what comes out of the function and then returns the result. Pretty cool. We&#8217;ve exercised our second right - to be able to pass functions into procedures. What about the first right? Well we sort of already had that with parameter &#8216;f&#8217; in the function &#8216;g&#8217; earlier. Lets look at another example:</p>
<p><code>int Foo()<br />
{<br />
  Func&lt;int , int&gt; bar = y =&gt; y + 5;<br />
  // …<br />
  return bar(56);<br />
}</code></p>
<p>We&#8217;ve kept our function around in a format that is very flexible. It hovers in a middle ground between program and data. If, like me, you have a procedural and imperative heritage - you regard anything that you can store, return and pass around as data. But when you can run that data as code, then the lines begin to get a little blurred.</p>
<p>The next right that we need to claim is the ability to return functions as values. We have all the machinery needed to do that now. If we can pass something into a function, then we could pass it straight out again. If we can create lambdas we can return them rather than use them or pass them into other functions. Here&#8217;s an example based on the function &#8216;g&#8217; earlier:</p>
<p><code>Func&lt;int , int&gt; H()<br />
{<br />
  return (int a) =&gt; a + 7;<br />
}</code></p>
<p>This is powerful - rather than give you the result of adding a number to some value you pass in, this function gives you a function that you can use to perform the function. you don&#8217;t need to know what the function is, just how to run it. Sounds like a perfect recipe for business rules. Obviously, adding numbers like that is trivial, but the principle can be applied to functions of great complexity. This can be lazy too - you can provide a function to calculate the result <em>when you need it </em>and not before. Think LINQ to SQL queries, that don&#8217;t incur the expense of hitting the DB until necessary.</p>
<p>The last right needed to be a first class functional citizen is also achieved through the capabilities that have been explained already (in the case of C# at least). If we can create a function and assign it to a variable, then we can do the same to a compound data structure. Here&#8217;s a slightly more elaborate example (thanks to <a href="http://www.paulstovell.com/blog/">Paul Stovell</a> for the idea):</p>
<p><code>public class MySwitcher&lt;T , R&gt;<br />
{<br />
Func&lt;T , bool&gt; Pred{get;set;}<br />
Func&lt;T , R&gt; Iffer{get;set;}<br />
Func&lt;T , R&gt; Elser{get;set;} </code></p>
<p><code>public MySwitcher(Func&lt;T , bool&gt; pred,<br />
  Func&lt;T , R&gt; iffer,<br />
  Func&lt;T , R&gt; elser)<br />
{<br />
  Pred = pred;<br />
  Iffer = iffer;<br />
  Elser = elser;<br />
}<br />
R Run(T input)<br />
{<br />
  if(Pred(input))<br />
  return Iffer(input);<br />
  return Elser(input);<br />
}<br />
}</code></p>
<p>This class keeps two functions around for later use. It also keeps a predicate function (a function that returns a yes/no answer) to decide which of them to use for a given piece of data. This could be used, for example, in a UI to decide between different ways to filter or render data based on some criteria.</p>
<p>I hope this very simple introduction shows you that not only does C# (and .NET 3.5 generally) now support functional programming, but that the arsenal of the functional programmer is very small and easy to learn. Next time around I hope to show you just how powerful these simple techniques can be.</p>
<p>[<span>1</span>] Abelson &amp; Sussman: the structure and interpretation of computer programs. 2ed. MIT Press. 1998.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aabs.wordpress.com/508/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aabs.wordpress.com/508/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aabs.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aabs.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aabs.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aabs.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aabs.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aabs.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aabs.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aabs.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aabs.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aabs.wordpress.com/508/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aabs.wordpress.com&blog=155386&post=508&subd=aabs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aabs.wordpress.com/2008/04/09/functional-programming-is-it-worth-your-time/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/aabs-128.jpg" medium="image">
			<media:title type="html">AABS</media:title>
		</media:content>
	</item>
		<item>
		<title>RIP Arnie Humour</title>
		<link>http://aabs.wordpress.com/2008/03/12/rip-arnie-humour/</link>
		<comments>http://aabs.wordpress.com/2008/03/12/rip-arnie-humour/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 09:00:31 +0000</pubDate>
		<dc:creator>Andrew Matthews</dc:creator>
		
		<category><![CDATA[Semantic Web]]></category>

		<guid isPermaLink="false">http://aabs.wordpress.com/2008/03/12/rip-arnie-humour/</guid>
		<description><![CDATA[My blogging has been pretty sporadic of late. My evenings have been spent working on a long SPARQL tutorial for IBM. It&#8217;s just going through the last editorial reviews now (with the good folks at Backstop Media) and should be published in a day or two.
 
Bob and Troy at Backstop are great editors, and [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>My blogging has been pretty sporadic of late. My evenings have been spent working on a long SPARQL tutorial for IBM. It&#8217;s just going through the last editorial reviews now (with the good folks at <a href="http://www.backstopmedia.com/" target="_blank">Backstop Media</a>) and should be published in a day or two.</p>
<p><a href="http://aabs.files.wordpress.com/2008/03/image.png"><img style="border-width:0;" border="0" alt="image" src="http://aabs.files.wordpress.com/2008/03/image-thumb.png?w=528" width="528"/></a> </p>
<p>Bob and Troy at Backstop are great editors, and their suggestions have kept the tutorial focused and much easier to understand. But I just had to find somewhere to put this snippet that they&#8217;ve asked me to cut. I know it&#8217;s unrelated to the tutorial, but it made me laugh.</p>
<blockquote><p>Arnie fans will know that, when presented with this question, it&#8217;s wise to lie. Joseki is faithful to a fault.
<pre>PREFIX u: &lt;http://purl.org/net/aabs/ont/users#&gt;</pre>
<pre> </pre>
<pre>ASK</pre>
<pre>{</pre>
<pre>&nbsp; ?x u:displayName "Sarah Connor".</pre>
<pre>}</pre>
</p>
<p>Let&#8217;s just hope that Joseki wasn&#8217;t planning on spending the evening in with her boyfriend: </p>
<p><code>ASK =&gt; true</code>.</p>
</blockquote>
<p>Let this be the last resting place of my daft attempts to make SPARQL funny.</p>
<div style="display:inline;margin:0;padding:0;" class="wlWriterSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/SPARQL" rel="tag">SPARQL</a>,<a href="http://del.icio.us/popular/Arnie" rel="tag">Arnie</a>,<a href="http://del.icio.us/popular/tutorial" rel="tag">tutorial</a>,<a href="http://del.icio.us/popular/semantic%20web" rel="tag">semantic web</a>,<a href="http://del.icio.us/popular/humour" rel="tag">humour</a>,<a href="http://del.icio.us/popular/humor" rel="tag">humor</a></div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aabs.wordpress.com/505/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aabs.wordpress.com/505/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aabs.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aabs.wordpress.com/505/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aabs.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aabs.wordpress.com/505/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aabs.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aabs.wordpress.com/505/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aabs.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aabs.wordpress.com/505/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aabs.wordpress.com/505/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aabs.wordpress.com/505/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aabs.wordpress.com&blog=155386&post=505&subd=aabs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aabs.wordpress.com/2008/03/12/rip-arnie-humour/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/aabs-128.jpg" medium="image">
			<media:title type="html">AABS</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/03/image-thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>First Forays into F#</title>
		<link>http://aabs.wordpress.com/2008/03/11/first-forays-into-f/</link>
		<comments>http://aabs.wordpress.com/2008/03/11/first-forays-into-f/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 09:00:11 +0000</pubDate>
		<dc:creator>Andrew Matthews</dc:creator>
		
		<category><![CDATA[106454]]></category>

		<guid isPermaLink="false">http://aabs.wordpress.com/2008/03/11/first-forays-into-f/</guid>
		<description><![CDATA[Since I&#8217;ve been doing a lot of LINQ in the last year or so, I figured that I could improve my C# 3.0 by improving my functional programming. I had two choices of language to explore: Haskell or F#. F# was the obvious choice, I&#8217;m doing this to be a better C# programmer, right? I [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Since I&#8217;ve been doing a lot of LINQ in the last year or so, I figured that I could improve my C# 3.0 by improving my functional programming. I had two choices of language to explore: Haskell or F#. F# was the obvious choice, I&#8217;m doing this to be a better C# programmer, right? I don&#8217;t want to depart too far from C# then.</p>
<p>I&#8217;m not going to give you the whole F# tutorial (though god knows someone needs to, cos the manual is poor). I&#8217;m just going to give you my first impressions: what it felt like to program in F#, what seemed nice, what could do with improvement, that sort of thing.</p>
<p>I often learn a new language by writing a Genetic Algorithm (GA). It gives me a few chances to explore the syntax, and it&#8217;s more interesting that a simple <u>hello world</u>. This time round, I wrote a GA to evolve strings with all ones. I know it&#8217;s pretty boring, but it&#8217;s easy to give an absolute score to an individual (just by counting the ratio of 1s to 0s). </p>
<h2>Scope rules and Immutability? Huh?</h2>
<p>My GA took up about 150 lines of code. That&#8217;s probably a little more terse than the equivalent C#, Java or C++ code. It&#8217;s a little unusual for me (being used to languages with curly braces everywhere) to work in a language that uses indentation to define scopes, but it took me all of about 10 minutes to find it completely natural. My initial confusion was compounded by the fact that my every instinct was telling me that variables were mutable and that I could pass and return in my functions. I had to catch myself a few times with that. For instance, to my untrained eye, the following looked OK:</p>
<pre><span style="color:rgb(0,0,255);">let</span> <span style="color:rgb(0,0,255);">rec</span> MyGeneticAlgorithm pop =
    generation &lt;- generation + 1
    <span style="color:rgb(0,0,255);">let</span> tmp = GetNextPop pop
    <span style="color:rgb(0,0,255);">if</span> (Pass(tmp) == false) <span style="color:rgb(0,0,255);">then
</span>        <span style="color:rgb(0,0,255);">let</span> tmp = MyGeneticAlgorithm(tmp)
    Display tmp
</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The tmp inside the else part and the tmp defined at the start of the function are completely unrelated, and when you invoke Display on tmp, you&#8217;re getting the first value. That mistake caught me over and over, till I ended up avoiding that approach altogether.</p>
<h2>Pipelines</h2>
<p>There were a few language features that were really nice to deal with. The first was pipeline operator ( <strong>|&gt;</strong> ). It allows you to compose functions, feeding the results from one into the next. It helps to make the flow of data in your code very clear.&nbsp; Here&#8217;s an example from the main loop of the GA:</p>
<pre><span style="color:rgb(0,0,255);">let</span> <span style="color:rgb(0,0,255);">rec</span> GeneticAlgorithm pop =
    generation &lt;- generation + 1
    <span style="color:rgb(0,0,255);">let</span> tmp = <strong>(pop |&gt; Score |&gt; Transition |&gt; Select |&gt; DisplayBestScoringIndividual)</strong>
    <span style="color:rgb(0,0,255);">if</span> (Pass(tmp)) <span style="color:rgb(0,0,255);">then
</span>        tmp
    <span style="color:rgb(0,0,255);">else
</span>        GeneticAlgorithm(tmp)
</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The section (pop |&gt; Score |&gt; Transition |&gt; Select |&gt; DisplayBestScoringIndividual) is easy to interpret.&nbsp; My functions were designed to allow composition, since I wanted to be able to take the result of a chain of function calls and assign it to some variable. here&#8217;s another nice example of using a pipeline and concatenating the result to another list:</p>
<pre><span style="color:rgb(0,0,255);">let</span> Transition pop =
    <span style="color:rgb(0,0,255);">let</span> new_generation = [<span style="color:rgb(0,0,255);">for</span> i <span style="color:rgb(0,0,255);">in</span> 0 .. 5 <span style="color:rgb(0,0,255);">-&gt;</span> Mate(SelectTwoMates(pop))]
    pop @ (new_generation  |&gt; MutatePopulation  |&gt; Score)
</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>In this example I select two mates randomly, five times, and mate them together. List1 <strong><em>@</em></strong> List2 concatenates List1 to List2 creating a new list. What I can do is pass my next generation of population members through a process of mutation and testing first, before I add them to the existing population. I could even have abbreviated it further:</p>
<pre>pop @ ([<span style="color:rgb(0,0,255);">for</span> i <span style="color:rgb(0,0,255);">in</span> 0 .. 5 <span style="color:rgb(0,0,255);">-&gt;</span> Mate(SelectTwoMates(pop))] |&gt; MutatePopulation |&gt; Score)
</pre>
<h2>Comprehensions</h2>
<p>The [for x in y -&gt; abc] syntax is called a <em>list comprehension. </em>It&#8217;s another nice piece of syntax that allows me to run a loop, invoke a function on the loop variable and create a list out of the results returned from each function invocation. The nearest C# equivalent (that I can think of) looks like this:</p>
<pre><span style="color:rgb(0,0,255);">var</span> myList = <span style="color:rgb(0,0,255);">new</span> <span style="color:rgb(43,145,175);">List</span>&lt;PopulationMember&gt;(<span style="color:rgb(43,145,175);">Enumerable</span>.Range(0, 5).Select(x =&gt; Mate(SelectTwoMates(pop))));
</pre>
<p>I think I prefer the F# syntax! You can do this for arrays and sequences too.</p>
<h2>Grokking the types</h2>
<p>The F# type system has parallels for many of the familiar .NET types. For example the <strong><em>list </em></strong>type is an extension of the List&lt;T&gt; type found in the System.Collection.Generic namespace. it provides a few additional methods to allow it to retain compatibility with OCaml. Sequences are the same as IEnumerables and arrays are the same as C# arrays. Anothe primitive data structure provided by F# is the <strong><em>tuple </em></strong>that allows you (kinda) to package data up in tiny anonymous structures for later concumption. the Syntax for tuples is easy to grasp, and being able to deal natively with them is extremely powerful.</p>
<h2>Things that seemed strange (to me)</h2>
<p>The first being the type notation for functional types. I&#8217;m still struggling to get my head around the type signatures for higher level functions (that take and consume functions). Time will tell how natural this will get for me, but for now I find it a little irritating to have to resort to &#8216;<em>so that&#8217;s a function that takes a function that takes an int and returns a function that..&#8221; </em>routine every time I get an intellisense pop-up.</p>
<p>Another thing I took a while to get used to was not surrounding the arguments to a method with parentheses and separating them with commas. If I invoke a method with that notation I end up passing it a tuple with each of the parameters as parts. Which may be appropriate, or not. If you want to include the results of a method invocation in the parameter list, you then have to surround it with parentheses.</p>
<p>I was really thrown by the lack of implicit type casting when dealing with integers and floats and singles etc. My first programming language was C, and every language since then has used implict type conversion where it was safe to do so. Casting the integer 2 to be a float should be perfectly safe. But F# refuses to do it for me behind the scenes. I end up with code like this:</p>
<pre><span style="color:rgb(0,0,255);">let</span> FitnessFunction (g:int list) : float =
    <span style="color:rgb(0,0,255);">let</span> totalOnes = Sum(g.Map(<span style="color:rgb(0,0,255);">fun</span> i <span style="color:rgb(0,0,255);">-&gt;</span> float i))
    float totalOnes / float g.Length
</pre>
<p>Apart from the final division, most of this should have been possible simply because a conversion from an int to a float involves no possible loss of precision. pity.</p>
<p>Another irritation is the lack of signposts to good documentation. Naturally, because F# is a product, MS don&#8217;t want to point out to you that F# is very close in syntax to OCaml (or at least, that&#8217;s how it seems). I tried to get by on the F# manuals, which were way too brief and short on examples. What I didn&#8217;t realise initially is that OCaml has a lively open source community and that means there are some good quality tutorials and language guides about.</p>
<h2>Things that seemed cool (to me)</h2>
<p>There are always a few things that take longer to fix in your mind when you are learning a new language. I never studied functional programming in university. Our campus opted in favour of Design By Contract &amp; Eiffel. I wish, now, that it had been otherwise. I&#8217;ve really enjoyed my first foray into F#. I think the code I&#8217;m able to write is easy to read. When I got my head around the scoping and immutability rules, my code just worked straight away. Not only that, it was fast. I was able to fly through a couple of thousand generations with 100 individuals each with a genome of 100 bits in about 1s. That&#8217;s about a millisecond per generation. I was worried initially that all this copy was going to slow me down. It seems not.</p>
<h2>Some Useful References</h2>
<ol>
<li><a href="http://www.ocaml-tutorial.org/" target="_blank">Objective Caml Tutorial</a>
</li>
<li><a href="http://caml.inria.fr/pub/docs/manual-ocaml/index.html" target="_blank">The Objective Caml system</a> by Xavier Leroy
</li>
<li><a href="\Program Files\FSharp-1.9.3.14\manual\library.html" target="_blank">The F# Manual</a></li>
</ol>
<div style="display:inline;margin:0;padding:0;" class="wlWriterSmartContent">del.icio.us Tags: <a href="http://del.icio.us/popular/GA" rel="tag">GA</a>,<a href="http://del.icio.us/popular/genetic%20algorithm" rel="tag">genetic algorithm</a>,<a href="http://del.icio.us/popular/AI" rel="tag">AI</a>,<a href="http://del.icio.us/popular/F#" rel="tag">F#</a>,<a href="http://del.icio.us/popular/OCaml" rel="tag">OCaml</a>,<a href="http://del.icio.us/popular/functional%20programming" rel="tag">functional programming</a>,<a href="http://del.icio.us/popular/C#" rel="tag">C#</a>,<a href="http://del.icio.us/popular/dotnet" rel="tag">dotnet</a>,<a href="http://del.icio.us/popular/.NET" rel="tag">.NET</a></div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aabs.wordpress.com/502/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aabs.wordpress.com/502/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aabs.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aabs.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aabs.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aabs.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aabs.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aabs.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aabs.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aabs.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aabs.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aabs.wordpress.com/502/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aabs.wordpress.com&blog=155386&post=502&subd=aabs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aabs.wordpress.com/2008/03/11/first-forays-into-f/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/aabs-128.jpg" medium="image">
			<media:title type="html">AABS</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Task Scheduler For GTD with OneNote 2007</title>
		<link>http://aabs.wordpress.com/2008/02/12/using-task-scheduler-for-gtd-with-onenote-2007/</link>
		<comments>http://aabs.wordpress.com/2008/02/12/using-task-scheduler-for-gtd-with-onenote-2007/#comments</comments>
		<pubDate>Mon, 11 Feb 2008 22:37:10 +0000</pubDate>
		<dc:creator>Andrew Matthews</dc:creator>
		
		<category><![CDATA[Readify]]></category>

		<guid isPermaLink="false">http://aabs.wordpress.com/2008/02/12/using-task-scheduler-for-gtd-with-onenote-2007/</guid>
		<description><![CDATA[Aymeric Gaurat-Apelli, against my will, has got me hooked on using OneNote, and like many people I started using it for organisation with GTD. I set up my OneNote the way that Rob from 7Breaths described in his great blog series. But I found that I still need a little prompting from time to time. [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://aymeric.gaurat.net/" target="_blank">Aymeric Gaurat-Apelli</a>, against my will, has got me hooked on using OneNote, and like many people I started using it for organisation with <a href="http://www.google.com.au/url?sa=t&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FGetting_Things_Done&amp;ei=SMmwR-ngHqTIswKI0qnwCQ&amp;usg=AFQjCNHi9227WDd1uvPMy9kZTRrMcKJIxA&amp;sig2=k1UKesK9RZVMxE_zsdAEXA" target="_blank">GTD</a>. I set up my OneNote the way that Rob from <a href="http://www.blog.7breaths.co.uk" target="_blank">7Breaths</a> described in his <a href="http://www.blog.7breaths.co.uk/2007/04/gtd-with-onenote-set-up.html" target="_blank">great blog series</a>. But I found that I still need a little prompting from time to time. So I found a neat way to shove OneNote in my face at the beginning and end of every day to &#8216;gently&#8217; persuade me to gather and process my tasks for the day.</p>
<p>If you&#8217;ve got your OneNote set up according to Rob&#8217;s method, you&#8217;ll have a TODAY section, and in that you&#8217;ll gather your daily notes, clippings etc for later processing and organisation. I just added a couple of pages and then I invoke them at preset times of the day. Here&#8217;s how you do it.</p>
<p>First Create your page in the TODAY section. It doesn&#8217;t matter what you call it. I called mine the &#8220;<i>Brain Dump Area</i>&#8220;:</p>
<p><a href="http://aabs.files.wordpress.com/2008/02/image.png"><img src="http://aabs.files.wordpress.com/2008/02/image-thumb.png?w=570&h=414" style="border-width:0;" alt="image" height="414" width="570" /></a></p>
<p>See what I mean about gentle? Next I create a scheduled task using the (for Vista) Task Scheduler. You&#8217;ll find this in your admin tools menu off the start menu:</p>
<p><a href="http://aabs.files.wordpress.com/2008/02/image1.png"><img src="http://aabs.files.wordpress.com/2008/02/image-thumb1.png?w=426&h=128" style="border-width:0;" alt="image" height="128" width="426" /></a></p>
<p>in the task pane, select &#8220;Create Basic Task&#8221;</p>
<p><a href="http://aabs.files.wordpress.com/2008/02/image2.png"><img src="http://aabs.files.wordpress.com/2008/02/image-thumb2.png?w=272&h=197" style="border-width:0;" alt="image" height="197" width="272" /></a></p>
<p>Give it a name</p>
<p><a href="http://aabs.files.wordpress.com/2008/02/image3.png"><img src="http://aabs.files.wordpress.com/2008/02/image-thumb3.png?w=714&h=496" style="border-width:0;" alt="image" height="496" width="714" /></a></p>
<p>Select a daily task, run on whatever schedule you like, then click through to actions, and select the &#8220;Start a Program&#8221; option</p>
<p><a href="http://aabs.files.wordpress.com/2008/02/image4.png"><img src="http://aabs.files.wordpress.com/2008/02/image-thumb4.png?w=334&h=92" style="border-width:0;" alt="image" height="92" width="334" /></a></p>
<p>You&#8217;ll be presented with an option to enter the program location, some command line arguments and an optional area to select where the program gets run. Locate your instance of OneNote (mine&#8217;s at &#8220;C:\Program Files\Microsoft Office\Office12\ONENOTE.EXE&#8221;) and enter its path in the program area. Then go to OneNote and navigate to the page you created, and right click on the page tab. Select the &#8220;Copy Hyperlink to this Page&#8221; option, and then go back to Task Scheduler.</p>
<p><a href="http://aabs.files.wordpress.com/2008/02/image5.png"><img src="http://aabs.files.wordpress.com/2008/02/image-thumb5.png?w=296&h=230" style="border-width:0;" alt="image" height="230" width="296" /></a></p>
<p>In the &#8220;Add Arguments (optional):&#8221; text box enter: <b>/hyperlink &#8220;&#8221; </b>and between the quotes paste the hyperlink from the page you created in OneNote. Mine looked like this:</p>
<p><b>/hyperlink &#8220;onenote://C:/Users/Andrew%20Matthews/Documents/OneNote%20Notebooks/GettingThingsDone/<br />
TODAY.one#Brain%20Dump%20Area&amp;section-id={DD18A524-CB73-47D9-A152-778C2116DA01}&amp;<br />
page-id={0F370401-83D6-4BB3-B2CC-7266A16395B7}&amp;end&#8221;</b></p>
<p>Yours will be different, but similar. Click through to the finish button, and you&#8217;re done. If you right click on the task entry and select Run, you can see what it will do. It starts OneNote selecting the Brain Dump Page for immediate display.</p>
<p>Now all I have to do is resist the urge to hit Snooze, and I&#8217;ll be really organised.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/aabs.wordpress.com/501/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/aabs.wordpress.com/501/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aabs.wordpress.com/501/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aabs.wordpress.com/501/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aabs.wordpress.com/501/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aabs.wordpress.com/501/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aabs.wordpress.com/501/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aabs.wordpress.com/501/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aabs.wordpress.com/501/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aabs.wordpress.com/501/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aabs.wordpress.com/501/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aabs.wordpress.com/501/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aabs.wordpress.com&blog=155386&post=501&subd=aabs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://aabs.wordpress.com/2008/02/12/using-task-scheduler-for-gtd-with-onenote-2007/feed/</wfw:commentRss>
	
		<media:content url="http://a.wordpress.com/avatar/aabs-128.jpg" medium="image">
			<media:title type="html">AABS</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/02/image-thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/02/image-thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/02/image-thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/02/image-thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/02/image-thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://aabs.files.wordpress.com/2008/02/image-thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>