<?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>greynode &#187; programming</title>
	<atom:link href="http://greynode.org/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://greynode.org</link>
	<description>ingénierie de tous les aspects de vie</description>
	<lastBuildDate>Wed, 11 Aug 2010 04:10:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Python 2 to 3</title>
		<link>http://greynode.org/2009/12/02/python-2-to-3/</link>
		<comments>http://greynode.org/2009/12/02/python-2-to-3/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 18:11:12 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://greynode.org/?p=157</guid>
		<description><![CDATA[Updating to Python 3? I found a nice cheat sheet by Mark Summerfield that shows a concise summary of the differences between Python 2 and Python 3, as well as some of the more common features of Python 3. This document is freely available from InformIT&#8217;s website, but I have also mirrored it. Download the [...]]]></description>
			<content:encoded><![CDATA[<p>Updating to <a href="http://docs.python.org/3.1/">Python 3</a>? I found a nice cheat sheet by <a href="http://www.informit.com/authors/bio.aspx?a=920D82F2-8CBB-4973-9A76-F7EA84E7BF39">Mark Summerfield</a> that shows a concise summary of the differences between Python 2 and Python 3, as well as some of the more common features of Python 3.</p>
<p>This document is freely available from InformIT&#8217;s website, but I have also mirrored it. Download the cheat sheet below.</p>
<blockquote><p>
<a href="http://greynode.org/mirror/python2python3.pdf" target="_blank">Python2Python3.pdf</a> from greynode.org</p>
<p><a href="http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/python/python2python3.pdf" target="_blank">Python2Python3.pdf</a> from InformIT&#8217;s site
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/12/02/python-2-to-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automake and Autoconf Made Simple</title>
		<link>http://greynode.org/2009/11/02/automake-and-autoconf-made-simple/</link>
		<comments>http://greynode.org/2009/11/02/automake-and-autoconf-made-simple/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 08:15:14 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[GNU]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://greynode.org/?p=142</guid>
		<description><![CDATA[Instead of randomly pasting configuration code from other projects when you decide you want to use automake/autoconf, just check out all you should really know about autoconf and automake. Albeit, it may not be comprehensive, but it should get you started.]]></description>
			<content:encoded><![CDATA[<p>Instead of randomly pasting configuration code from other projects when you decide you want to use automake/autoconf, just check out <a href="http://smalltalk.gnu.org/blog/bonzinip/all-you-should-really-know-about-autoconf-and-automake">all you should really know about autoconf and automake</a>. Albeit, it may not be comprehensive, but it should get you started.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/11/02/automake-and-autoconf-made-simple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby from Other Languages</title>
		<link>http://greynode.org/2009/10/25/ruby-from-other-languages/</link>
		<comments>http://greynode.org/2009/10/25/ruby-from-other-languages/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 05:06:30 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://greynode.org/?p=134</guid>
		<description><![CDATA[I was just browsing around for some material on ruby and I found this page very helpful: http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/ It&#8217;s not a ruby bible or anything, but I think it is a good intro for experienced programmers.]]></description>
			<content:encoded><![CDATA[<p>I was just browsing around for some material on ruby and I found this page very helpful:</p>
<p><a href="http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/">http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/</a></p>
<p>It&#8217;s not a ruby bible or anything, but I think it is a good intro for experienced programmers.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/10/25/ruby-from-other-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prefixes for Binary Multiples</title>
		<link>http://greynode.org/2009/06/26/prefixes-for-binary-multiples/</link>
		<comments>http://greynode.org/2009/06/26/prefixes-for-binary-multiples/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 21:57:47 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[IEEE]]></category>
		<category><![CDATA[international standards]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://greynode.org/?p=83</guid>
		<description><![CDATA[I have become increasingly frustrated with people refusing to adopt the IEEE 1541-2002 standard. There is no real good reason why it should not be adopted. I think the most common argument I have heard against it is, &#8220;That&#8217;s stupid! The people who made that up are stupid! You&#8217;re stupid for using it!&#8221; That is [...]]]></description>
			<content:encoded><![CDATA[<p>I have become increasingly frustrated with people refusing to adopt the <a title="IEEE 1541" href="http://en.wikipedia.org/wiki/IEEE_1541">IEEE 1541-2002 standard</a>. There is no real good reason why it should not be adopted. I think the most common argument I have heard against it is, &#8220;That&#8217;s stupid! The people who made that up are stupid! You&#8217;re stupid for using it!&#8221; That is to say, there are no very good arguments against it.</p>
<p>In fact the longer people continue to use the old terminology, the longer the hard drive manufacturers have to use the old terminology to rip off consumers. Did you ever wonder why your hard drive isn&#8217;t a full 80GiB? <strong>That&#8217;s because it said 80GB on the box.</strong></p>
<p>Some argue that it makes no sense to have the extra terminology because computers operate using base 2. The problem with this argument is that the <a href="http://en.wikipedia.org/wiki/International_Bureau_of_Weights_and_Measures">International Bureau of Weights and Measures</a> published a paper in 1998 stating that SI prefixes should only be used with <em>powers of 10. </em></p>
<p>I think anyone familiar with science understands the necessity for proper measurements. Without them, your data is bad. Let me present a quick example. Let&#8217;s say you were looking for a place to store copies of your digital movies. Your computer says they are 4.7GB (but it really means <strong>GiB</strong>), so you decide to get a 1TB hard drive in which you think you can store 1,000 / 4.7 = 212 full movies. However, the 1TB hard drive is really only 909GiB, which means you can only store about 193 movies. If you leave 20% free space to keep performance up, then that&#8217;s only 154 movies.</p>
<p>But the data on the hard drive box was not misrepresented, it was misunderstood. The reason it was misunderstood is because the neglect of the standard passes from the programmer to the average user via the software they use. There I said it, it is your fault programmers.</p>
<p>If you think you have a real reason why not to adopt it, please leave a comment.</p>
<p>A quick explanation of the standard, courtesy of <a href="http://www.wikipedia.org">wikipedia</a>:</p>
<blockquote>
<p style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.5em;">IEEE 1541 recommends:</p>
<ul style="line-height: 1.5em; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 1.5em; list-style-image: url(http://en.wikipedia.org/skins-1.5/monobook/bullet.gif); padding: 0px;">
<li style="margin-bottom: 0.1em;">a set of units to refer to quantities used in digital electronics and computing:
<ul style="line-height: 1.5em; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 1.5em; list-style-image: url(http://en.wikipedia.org/skins-1.5/monobook/bullet.gif); padding: 0px;">
<li style="margin-bottom: 0.1em;"><em>bit</em> (symbol &#8216;b&#8217;), a binary digit;</li>
<li style="margin-bottom: 0.1em;"><em>byte</em> (symbol &#8216;B&#8217;), a set of adjacent bits (usually, but not necessarily, eight) operated on as a group;</li>
<li style="margin-bottom: 0.1em;"><em>octet</em> (symbol &#8216;o&#8217;), a group of eight bits;</li>
</ul>
</li>
<li style="margin-bottom: 0.1em;">a set of prefixes to indicate binary multiples of the aforesaid units:
<ul style="line-height: 1.5em; list-style-type: square; margin-top: 0.3em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 1.5em; list-style-image: url(http://en.wikipedia.org/skins-1.5/monobook/bullet.gif); padding: 0px;">
<li style="margin-bottom: 0.1em;"><em>kibi</em> (symbol &#8216;Ki&#8217;), 2<sup>10</sup> = <span style="white-space: nowrap;">1<span style="margin-left: 0.25em;">024</span></span>;</li>
<li style="margin-bottom: 0.1em;"><em>mebi</em> (symbol &#8216;Mi&#8217;), 2<sup>20</sup> = <span style="white-space: nowrap;">1<span style="margin-left: 0.25em;">048</span><span style="margin-left: 0.25em;">576</span></span>;</li>
<li style="margin-bottom: 0.1em;"><em>gibi</em> (symbol &#8216;Gi&#8217;), 2<sup>30</sup> = <span style="white-space: nowrap;">1<span style="margin-left: 0.25em;">073</span><span style="margin-left: 0.25em;">741</span><span style="margin-left: 0.25em;">824</span></span>;</li>
<li style="margin-bottom: 0.1em;"><em>tebi</em> (symbol &#8216;Ti&#8217;), 2<sup>40</sup> = <span style="white-space: nowrap;">1<span style="margin-left: 0.25em;">099</span><span style="margin-left: 0.25em;">511</span><span style="margin-left: 0.25em;">627</span><span style="margin-left: 0.25em;">776</span></span>;</li>
<li style="margin-bottom: 0.1em;"><em>pebi</em> (symbol &#8216;Pi&#8217;), 2<sup>50</sup> = <span style="white-space: nowrap;">1<span style="margin-left: 0.25em;">125</span><span style="margin-left: 0.25em;">899</span><span style="margin-left: 0.25em;">906</span><span style="margin-left: 0.25em;">842</span><span style="margin-left: 0.25em;">624</span></span>;</li>
<li style="margin-bottom: 0.1em;"><em>exbi</em> (symbol &#8216;Ei&#8217;), 2<sup>60</sup> = <span style="white-space: nowrap;">1<span style="margin-left: 0.25em;">152</span><span style="margin-left: 0.25em;">921</span><span style="margin-left: 0.25em;">504</span><span style="margin-left: 0.25em;">606</span><span style="margin-left: 0.25em;">846</span><span style="margin-left: 0.25em;">976</span></span>;</li>
</ul>
</li>
<li style="margin-bottom: 0.1em;">that the first part of the binary prefix is pronounced as the analogous SI prefix, and the second part is pronounced as <em>bee</em>;</li>
<li style="margin-bottom: 0.1em;">that SI prefixes are not used to indicate binary multiples.</li>
</ul>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/06/26/prefixes-for-binary-multiples/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Multicore Programming Primer</title>
		<link>http://greynode.org/2009/06/26/multicore-programming-primer/</link>
		<comments>http://greynode.org/2009/06/26/multicore-programming-primer/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 16:41:02 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[multicore]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[PS3]]></category>

		<guid isPermaLink="false">http://greynode.org/?p=79</guid>
		<description><![CDATA[MIT has been offering free videos of various courses for quite a while now. Today I came across this video series on multicore programming. I haven&#8217;t watched but a few minutes of it so far, but I am hoping to watch all of them before the next semester starts if it proves to be useful [...]]]></description>
			<content:encoded><![CDATA[<p><a title="MIT" href="http://www.mit.edu">MIT</a> has been offering free videos of various courses for quite a while now. Today I came across this <a href="http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-189January--IAP--2007/CourseHome/index.htm">video series on multicore programming</a>. I haven&#8217;t watched but a few minutes of it so far, but I am hoping to watch all of them before the next semester starts if it proves to be useful in some way. It uses the PS3 framework &#8212; I am not sure if this poses an issue with using the videos yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/06/26/multicore-programming-primer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Functional Programming with the Unix Command Line</title>
		<link>http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/</link>
		<comments>http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 06:29:30 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[one liners]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting languages]]></category>

		<guid isPermaLink="false">http://greynode.org/?p=66</guid>
		<description><![CDATA[I was pondering the unix command line the other day while reading sed &#38; awk, and I came to the following revelation: variables aside, the unix command line is a lot like functional programming. Using the command line, you can build a functional program by redirecting I/O between various programs, or functions. Many of the [...]]]></description>
			<content:encoded><![CDATA[<p>I was pondering the unix command line the other day while reading <em>sed &amp; awk</em>, and I came to the following revelation: variables aside, the unix command line is a lot like functional programming. Using the command line, you can build a functional program by redirecting I/O between various programs, or <em>functions</em>. Many of the programs one uses to build one-liners are essentially <a href="http://en.wikipedia.org/wiki/Pure_function"><strong>pure functions</strong></a>. An example of a pure function on the unix command line might be the programs <em>uniq</em> or <em>sort</em>. Various other functions such as <em>ps</em> and <em>wget</em> are not so pure, as their output relies on I/O with the operating sytem or server.</p>
<p>All theory aside, here are a few good one-liners.</p>
<h2>Uploading Files</h2>
<blockquote>
<pre>tar cjvf - yourDirectory | ssh uname@host "cat &gt; yourDirectory.tar.bz2"</pre>
</blockquote>
<p>This command will create an archive of &#8220;yourDirectory&#8221; and upload it to your server via SSH, all in one chained command. Quite handy for uploading local content for sharing or backup.</p>
<p><strong>Edit:</strong> Apparently this command transfers large files extremely slow. Oops.</p>
<h2>Checking FreeBSD UPDATING File Automatically</h2>
<blockquote>
<pre>portversion | awk '/&lt;/ {print $1}' |
xargs -I '{}' awk '/AFFECTS:.*{}/ {print}' /usr/ports/UPDATING &gt; updates.txt</pre>
</blockquote>
<p>Ok. So this command pertains to the FreeBSD ports system. It is not recommended that you upgrade all your ports at once. There is often information contained in the file /usr/ports/UPDATING about special instructions you may have to follow while upgrading a package. Often times you may have to recompile other packages, or add a line to a configuration file, etc. The string above will check all of the ports tht are out of date, and compare them to the UPDATING file to see if the package is contained. If it is, it writes the name of that port to updates.txt. You can then use this file to know which ports have special instructions. You should probably write an alias for this one.</p>
<h2>Converting Line Endings</h2>
<p>The following two commands should help with reformatting files. Often times I find myself getting web designs from someone who uses windows. Most editors on windows will save files with DOS line endings. When you open one of these files in unix (in certain editors), the line endings won&#8217;t appear properly. The following commands will circumvent this problem, in either situation.</p>
<h3>Convert from unix (\n) to DOS (\r\n)</h3>
<blockquote>
<pre>awk '{sub(/$/, "\r")};1' unix_endings.txt &gt; dos_endings.txt</pre>
</blockquote>
<h3>Convert from DOS (\r\n) to unix (\n)</h3>
<blockquote>
<pre>awk '{sub(/\r$/, "")};1' dos_endings.txt &gt; unix_endings.txt</pre>
</blockquote>
<p>And yes, I realize that I use too many commas when I write: I&#8217;m working on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/06/25/functional-programming-with-the-unix-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating Rails on OS X</title>
		<link>http://greynode.org/2009/06/23/updating-rails-on-os-x/</link>
		<comments>http://greynode.org/2009/06/23/updating-rails-on-os-x/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 02:04:17 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://greynode.org/?p=60</guid>
		<description><![CDATA[If you install XCode for OS X 10.5, it automatically comes with a version of rails. This is (generally) not the latest version however, and you must take a few steps to update it. First you need to update rubygems with the following: macintosh$ sudo gem install rubygems-update macintosh$ sudo update_rubygems After updating rubygems, you [...]]]></description>
			<content:encoded><![CDATA[<p>If you install XCode for OS X 10.5, it automatically comes with a version of rails. This is (generally) not the latest version however, and you must take a few steps to update it. First you need to update rubygems with the following:</p>
<blockquote>
<pre>macintosh$ sudo gem install rubygems-update</pre>
<pre>macintosh$ sudo update_rubygems</pre>
</blockquote>
<p>After updating rubygems, you should be able to update the rest of your gems without a problem (including rails) via the following:</p>
<blockquote>
<pre>macintosh$ sudo gem update</pre>
</blockquote>
<p>After that you should be ready to build a rails app.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/06/23/updating-rails-on-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting Languages</title>
		<link>http://greynode.org/2009/06/22/scripting-languages/</link>
		<comments>http://greynode.org/2009/06/22/scripting-languages/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 22:02:04 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[GNU]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting languages]]></category>

		<guid isPermaLink="false">http://www.greynode.org/?p=48</guid>
		<description><![CDATA[I just thought I&#8217;d share with you Random thoughts on scripting languages by Brian Kernighan. After reading this, I looked up the source code to the unix utility wc. The GNU wc program was written in C, and amounted to about 800 lines with comments. A similar program written in awk is a mere 2 [...]]]></description>
			<content:encoded><![CDATA[<p>I just thought I&#8217;d share with you <a title="Random thoughts on scripting languages by Brian Kernighan" href="http://www.greynode.org/pdf/CS152-Lecture_14-Kernighan.pdf">Random thoughts on scripting languages by Brian Kernighan</a>.</p>
<p>After reading this, I looked up the <a title="source code for coreutils" href="http://www.gnu.org/software/coreutils/">source code to the unix utility wc</a>. The GNU <em>wc</em> program was written in C, and amounted to about 800 lines with comments. A similar program written in <a title="awk" href="http://www.gnu.org/manual/gawk/gawk.html"><strong>awk</strong></a> is a mere 2 lines long:</p>
<blockquote>
<pre>{ nc += length($0) + 1; nw += NF }
END { print NR, "lines", nw, "words", nc, "characters" }</pre>
</blockquote>
<p>I know you are probably thinking that I just made an unfair comparison. Yes, I did.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/06/22/scripting-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Haskell</title>
		<link>http://greynode.org/2009/05/17/9/</link>
		<comments>http://greynode.org/2009/05/17/9/#comments</comments>
		<pubDate>Mon, 18 May 2009 06:56:20 +0000</pubDate>
		<dc:creator>Jeff Aigner</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.greynode.org/?p=9</guid>
		<description><![CDATA[I have recently been continuing my journey with Haskell, the purely functional programming language. I had dabbled with it a little bit over the winter, but haven&#8217;t had much practice since then. It is my hope that over the summer I will be able to get a fair amount of practice with the language. I [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently been continuing my journey with <a href="http://www.haskell.org">Haskell</a>, the <a href="http://www.haskell.org/haskellwiki/Functional_programming" target="_blank">purely functional programming language</a>. I had dabbled with it a little bit over the winter, but haven&#8217;t had much practice since then. It is my hope that over the summer I will be able to get a fair amount of practice with the language.</p>
<p>I have settled on using the book <a href="http://www.realworldhaskell.org/" target="_blank">Real World Haskell</a> as my first stepping stone. It has gotten good reviews, and was recommended to me by one of my professors. There is a <a href="http://book.realworldhaskell.org/read/">free version of it online</a>, if you wish to check it out. It uses quite a bit of comparison with imperative languages, at least in the early chapters, so I don&#8217;t recommend it to someone who has never programmed before.</p>
<p>For those of you who are not familiar with functional programming, I am going to present to you a few problems and the elegant solutions provided by Haskell. The first I will show you is an implementation of quicksort.</p>
<pre>qsort (x:xs) = qsort (filter (&lt; x) xs) ++ [x] ++ qsort (filter (&gt;= x) xs)</pre>
<p>This implementation of quicksort is so clean it makes me sick. It is essentially the definition of the quicksort algorithm. Because of the facilities provided by Haskell, it translates quite nicely.</p>
<p>Another problem I&#8217;d like to show you involves counting. Say you had a string of words, and you would like to count the number of words that start with an upper-case letter. In an imperative language, this might involve several loops and/or the use of regular expressions. With Haskell, its a simple matter of function composition. Have a look:</p>
<pre>capCount = length . filter (isUpper . head) . words</pre>
<p>This might look odd if you are not familiar with functional programming or function composition, but it is a really simple function. The &#8216;.&#8217; operator simply takes the output from the function on the right, and feeds it into the function on the left. The &#8216;words&#8217; function breaks a string up into a list of words wherever there is a space. The &#8216;head&#8217; function returns the first element of the list, &#8216;isUpper&#8217; will return a boolean value saying whether or not a Character is upper-case, &#8216;filter&#8217; applies a function over a list and removes items that evaluate to False, and &#8216;length&#8217; returns the length of the list. As you can see, it&#8217;s much easier to describe with code than with words.</p>
<p>Anyway, I will be posting anything I find interesting on here. Hopefully someone other than myself will benefit from it.</p>
]]></content:encoded>
			<wfw:commentRss>http://greynode.org/2009/05/17/9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->