<?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>James Keane</title>
	<atom:link href="http://jameskeane.ca/feed" rel="self" type="application/rss+xml" />
	<link>http://jameskeane.ca</link>
	<description>The Life Experiment</description>
	<lastBuildDate>Fri, 09 Apr 2010 12:55:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>C++0x Lazy List</title>
		<link>http://jameskeane.ca/programming/cpp0x-lazy-list</link>
		<comments>http://jameskeane.ca/programming/cpp0x-lazy-list#comments</comments>
		<pubDate>Sat, 03 Apr 2010 04:39:25 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++0x]]></category>

		<guid isPermaLink="false">http://jameskeane.ca/?p=143</guid>
		<description><![CDATA[An implementation of a lazy list in c++ using new lambda features of c++0x.  A simple example using Fibonacci numbers is demonstrated.]]></description>
			<content:encoded><![CDATA[<p>One of my favorite features of Haskell will always be lazy lists.  When I first saw it I was blown away, it was the coolest thing I&#8217;ve ever seen a programming language do (with exception to prolog&#8217;s unification).  Ever since I&#8217;ve been disappointed with c++ for not being able to do it as elegantly.</p>
<p>Basically, for those who don&#8217;t know, a lazy list is an infinite list in which elements are generated on the fly.  Although this has been possible in C++ for a long time, with C++0x it really becomes beautiful.</p>
<p>For example, to represent the Fibonacci Numbers we can do:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">LazyList<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> fibonacci<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> index, LazyList<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> <span style="color: #000040;">*</span>obj<span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span> <span style="color: #0000ff;">int</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>index <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">return</span> index<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>obj<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span>index<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000040;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">*</span>obj<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span>index<span style="color: #000040;">-</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* Print the first 20 fibonacci numbers */</span>
<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">20</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
	<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;%d &quot;</span>, fibonacci<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>And the code for class LinkedList<T> (Note: I have not implemented a cache, to show how simple it is):</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;functional&gt;</span>
<span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">class</span> LazyList 
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	<span style="color: #0000ff;">typedef</span> std<span style="color: #008080;">::</span><span style="color: #007788;">function</span><span style="color: #000080;">&lt;</span>T<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span>, LazyList<span style="color: #000080;">&lt;</span>T<span style="color: #000080;">&gt;</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #000080;">&gt;</span> Generator<span style="color: #008080;">;</span>
&nbsp;
	LazyList<span style="color: #008000;">&#40;</span>Generator gen<span style="color: #008000;">&#41;</span>
		<span style="color: #008080;">:</span> m_gen<span style="color: #008000;">&#40;</span>gen<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	T operator <span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> n<span style="color: #008000;">&#41;</span> 
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">return</span> m_gen<span style="color: #008000;">&#40;</span>n, <span style="color: #0000dd;">this</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
	Generator m_gen<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Awesome.</p>
]]></content:encoded>
			<wfw:commentRss>http://jameskeane.ca/programming/cpp0x-lazy-list/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spectrum</title>
		<link>http://jameskeane.ca/programming/spectrum</link>
		<comments>http://jameskeane.ca/programming/spectrum#comments</comments>
		<pubDate>Sat, 25 Jul 2009 20:58:00 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://jameskeane.ca/?p=126</guid>
		<description><![CDATA[I have been playing with Processing lately. It is surprisingly fun. I have created a visualization/spectrum analyzer, using code borrowed from: James Alliban. In my opinion this is the coolest part of processing, the idea that all code should be open sourced. You can check it out here.]]></description>
			<content:encoded><![CDATA[<p><a href="http://jameskeane.ca/files/Spectrum"><img class="alignnone size-full wp-image-127" title="Spectrum" src="http://jameskeane.ca/wp-content/uploads/2009/07/spectrum.jpg" alt="Spectrum" width="950" height="385" /></a></p>
<p>I have been playing with <a href="http://processing.org">Processing</a> lately.  It is surprisingly fun.</p>
<p>I have created a visualization/spectrum analyzer, using code borrowed from: <a href="http://jamesalliban.wordpress.com/2008/12/04/2d-ribbons/">James Alliban</a>.  In my opinion this is the coolest part of processing, the idea that all code <em>should</em> be open sourced.</p>
<p>You can check it out <a href="http://jameskeane.ca/files/Spectrum">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jameskeane.ca/programming/spectrum/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Discourse on Determinism</title>
		<link>http://jameskeane.ca/philosophy/discourse-on-determinism</link>
		<comments>http://jameskeane.ca/philosophy/discourse-on-determinism#comments</comments>
		<pubDate>Tue, 07 Jul 2009 06:45:10 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Philosophy]]></category>

		<guid isPermaLink="false">http://jameskeane.ca/?p=4</guid>
		<description><![CDATA[An interesting excerpt from the movie: Waking Life.]]></description>
			<content:encoded><![CDATA[<p>An interesting excerpt from the movie: <a href="http://en.wikipedia.org/wiki/Waking_Life">Waking Life</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jameskeane.ca/philosophy/discourse-on-determinism/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://jameskeane.ca/uncategorized/hello-world</link>
		<comments>http://jameskeane.ca/uncategorized/hello-world#comments</comments>
		<pubDate>Tue, 07 Jul 2009 05:02:03 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jameskeane.ca/?p=1</guid>
		<description><![CDATA[First Post! This is my website about my life, my thoughts, and my experiences. Â And it is still very much a work in progress, but wordpress is a very forgiving system and it should all be up and running very soon.]]></description>
			<content:encoded><![CDATA[<p>First Post!</p>
<p>This is my website about my life, my thoughts, and my experiences. Â And it is still very much a work in progress, but wordpress is a very forgiving system and it should all be up and running very soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://jameskeane.ca/uncategorized/hello-world/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
