<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>On The Balcony</title>
	<atom:link href="http://onthebalcony.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://onthebalcony.wordpress.com</link>
	<description></description>
	<lastBuildDate>Mon, 16 May 2011 20:17:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='onthebalcony.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>On The Balcony</title>
		<link>http://onthebalcony.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://onthebalcony.wordpress.com/osd.xml" title="On The Balcony" />
	<atom:link rel='hub' href='http://onthebalcony.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Haskell + lhs2TeX + LaTeX beamer</title>
		<link>http://onthebalcony.wordpress.com/2008/05/16/haskell-lhs2tex-latex-beamer/</link>
		<comments>http://onthebalcony.wordpress.com/2008/05/16/haskell-lhs2tex-latex-beamer/#comments</comments>
		<pubDate>Fri, 16 May 2008 21:13:19 +0000</pubDate>
		<dc:creator>Eelco Lempsink</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[lhs2tex]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[beamer]]></category>

		<guid isPermaLink="false">http://onthebalcony.wordpress.com/?p=31</guid>
		<description><![CDATA[For a presentation I&#8217;m currently building I want to walk the public through a bit of Haskell code. Because I want to make sure my code is runnable too, I decided to write it as Literal Haskell and then use lhs2TeX to convert it to very pretty LaTeX which I use to make a presention [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=31&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For a presentation I&#8217;m currently building I want to walk the public through a bit of Haskell code. Because I want to make sure my code is runnable too, I decided to write it as <a href="http://www.haskell.org/haskellwiki/Literate_programming">Literal Haskell</a> and then use <a href="http://people.cs.uu.nl/andres/lhs2tex/">lhs2TeX</a> to convert it to very pretty LaTeX which I use to make a presention PDF with <a href="http://latex-beamer.sourceforge.net/">LaTeX Beamer</a>.</p>
<p>This is pretty easy for the common use case (a (research) paper) about Haskell), but I had some more requirements. </p>
<ul>
<li>The code is split over several files</li>
<li>I want to mix code fragments of those files</li>
<li>I want effects, like uncovering code line by line</li>
</ul>
<p>It took me a couple of hours to figure out a sensible approach, which I describe here. I&#8217;m sure there are more ways to do it, and I&#8217;d love to hear them!</p>
<p>Since our lhs2TeX activities will be spread over multiple files, we&#8217;ll want to make a simple formatting file to share. Let&#8217;s call it &#8216;talk.fmt&#8217;</p>
<p><code><br />
%include polycode.fmt</p>
<p>% put formatting rules here<br />
</code></p>
<p>Then we set up our main LaTeX file.  Because we might want to use some code examples in there that are not in the files, let&#8217;s make it an lhs-file: &#8216;talk.lhs&#8217;.  In it&#8217;s preamble we define a couple of new LaTeX commands that are going to help us with making slides but referencing them in an arbitrary order.</p>
<p><code><br />
\documentclass{beamer}</p>
<p>%include talk.fmt</p>
<p>\newcommand{\ignore}[1]{}</p>
<p>\newcommand{\defslide}[2]{<br />
  \frame&lt;hidden&gt;[label=#1]{#2}<br />
}</p>
<p>\newcommand{\slide}[1]{\againframe&lt;1-&gt;{#1}}</p>
<p>\begin{document}</p>
<p>\include{Code}</p>
<p>\slide{thisisan}<br />
\slide{example}</p>
<p>\end{document}<br />
</code></p>
<p>First, we have &#8216;\ignore&#8217; to hide stuff from LaTeX that is only useful in the code and we don&#8217;t want to have in our presentation.</p>
<p>The &#8216;\defslide&#8217; command takes two arguments, a name which is used as a label to reference to and the contents for the slide.  The &#8216;&lt;hidden&gt;&#8217; makes sure that these slides will not be rendered.  In this case &#8216;hidden&#8217; is not a special argument, just a non-existing &#8216;mode&#8217;.</p>
<p>To use a defined slide, we use &#8216;\slide&#8217;, which uses &#8216;\againslide&#8217; to draw the slide, with all possible subframes (&#8216;&lt;1-&gt;&#8217;).</p>
<p>In the document body we include all the files which contain slides.  Note that this should be .tex file, generated from our .lhs file.  For example &#8216;Code.lhs&#8217; could look like this.</p>
<p><code><br />
%include talk.fmt</p>
<p>\ignore{<br />
module Code where<br />
}</p>
<p>\defslide{example}<br />
{<br />
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;example&nbsp;::&nbsp;IO&nbsp;()<br />
&gt;&nbsp;{-&quot;\uncover&lt;2-&gt;{&quot;-}&nbsp;example&nbsp;=&nbsp;putStrLn&nbsp;&quot;Hello!&quot;&nbsp;{-&quot;}&quot;-}<br />
}</p>
<p>\defslide{thisisan}{<br />
\frametitle{Just a normal frame}<br />
\begin{code}<br />
main :: IO ()<br />
main = undefined<br />
\end{code}}<br />
</code></p>
<p>I don&#8217;t uncourage anybody to mix styles like this, it&#8217;s just an a example, okay? <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   What you also see here is the way to uncover a piece of code line by line.  If you want to learn more about LaTeX Beamer I suggest you consult <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/beamer/doc/beameruserguide.pdf">the fine manual</a>.  </p>
<p>For easy use, we can make a Makefile to tie everything up. We also use <a href="http://www.phys.psu.edu/~collins/software/latexmk-jcc/">latexmk</a>, a simple tool that automagically processes the LaTeX file as many times as necessary, which saves a ton of time.</p>
<p><code><br />
default: talk.pdf</p>
<p>talk.pdf : Code.tex</p>
<p>%.pdf : %.tex<br />
&nbsp;&nbsp;&nbsp;&nbsp;latexmk -pdf $&lt;</p>
<p>%.tex : %.lhs talk.fmt<br />
&nbsp;&nbsp;&nbsp;&nbsp;lhs2TeX $&lt; &gt; $@</p>
<p>clean:<br />
&nbsp;&nbsp;&nbsp;&nbsp;latexmk -CA talk<br />
</code></p>
<p>If you want to try it for yourself just copy the above code to the mentioned filenames and run &#8216;make&#8217; to get the pdf. (Provided you have all the necessary requirements.)</p>
<p>(I think I massaged all the code so that it gets through WordPress&#8217; botching, but you&#8217;ll still need to replace the indenting spaces with tabs in the Makefile yourself.)</p>
<p>While in this example only one file with code is used, it easy to see that this way as many files as necessary can be used. As shown, the slides can be in arbitrary order and we can use nice LaTeX Beamer effects like uncovering. Hooray!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/onthebalcony.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/onthebalcony.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/onthebalcony.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/onthebalcony.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/onthebalcony.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/onthebalcony.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/onthebalcony.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/onthebalcony.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/onthebalcony.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/onthebalcony.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/onthebalcony.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/onthebalcony.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/onthebalcony.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/onthebalcony.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/onthebalcony.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/onthebalcony.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=31&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://onthebalcony.wordpress.com/2008/05/16/haskell-lhs2tex-latex-beamer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d1f2fc95154cef495bcbbde7d752f541?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">eelco</media:title>
		</media:content>
	</item>
		<item>
		<title>Just for fun: map as &#8216;higher-order function&#8217; in bash</title>
		<link>http://onthebalcony.wordpress.com/2008/03/08/just-for-fun-map-as-higher-order-function-in-bash/</link>
		<comments>http://onthebalcony.wordpress.com/2008/03/08/just-for-fun-map-as-higher-order-function-in-bash/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 13:01:33 +0000</pubDate>
		<dc:creator>Eelco Lempsink</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Shorties]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[map]]></category>

		<guid isPermaLink="false">http://onthebalcony.wordpress.com/?p=30</guid>
		<description><![CDATA[Defined recursively, of course: map () { if [ $# -le 1 ]; then return else local f=$1 local x=$2 shift 2 local xs=$@ $f $x map "$f" $xs fi } I&#8217;m not going to explain everything, but note the &#8216;local&#8217; commands to keep everything in function scope (to prevent strange bugs) and the quotes [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=30&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Defined recursively, of course:</p>
<pre>
map () {
  if [ $# -le 1 ]; then
    return
  else
    local f=$1
    local x=$2
    shift 2
    local xs=$@ 

    $f $x 

    map "$f" $xs
  fi
}</pre>
<p>I&#8217;m not going to explain everything, but note the &#8216;local&#8217; commands to keep everything in function scope (to prevent strange bugs) and the quotes around $f in the recursive call to prevent a &#8216;function call&#8217; of multiple words from being split.</p>
<p>Now you can do some completely nonsensical things, for which you really don&#8217;t need map, such as:</p>
<pre>
$ map touch aap noot mies</pre>
<p>But also slightly more useful things such as</p>
<pre>
$ map "echo foo" aap noot mies
foo aap
foo noot
foo mies 

$ map "echo file:" `ls`
file: aap
file: noot
file: mies</pre>
<p>To open up some more possibilities, I also defined a &#8216;rota&#8217; function, with <strong>rot</strong>ates the <strong>a</strong>rguments of a command such that the last comes first.</p>
<pre>
rota () {
  local f=$1
  shift
  local args=($@)
  local idx=$(($#-1))
  local last=${args[$idx]}
  args[$idx]= 

  $f $last ${args[@]}
}</pre>
<p>I&#8217;m using a array (yes, bash has arrays) to easily get the last element, as you can see <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>So, how about&#8230;</p>
<pre>
$ map "rota mv /tmp" aap noot mies</pre>
<p>(Move the aap, noot and mies file to /tmp)</p>
<p>There are probably better (and more useful) examples of it&#8217;s usage, but you hopefully get the gist of it.</p>
<p>This code is just for fun (I don&#8217;t expect I&#8217;m ever going to use it, even), so it&#8217;s nowhere near being robust.  There are a lot of (possible) bugs concerning spaces and undetected grouping of words (with double quotes). Use at your own risk <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/onthebalcony.wordpress.com/30/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/onthebalcony.wordpress.com/30/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/onthebalcony.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/onthebalcony.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/onthebalcony.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/onthebalcony.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/onthebalcony.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/onthebalcony.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/onthebalcony.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/onthebalcony.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/onthebalcony.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/onthebalcony.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/onthebalcony.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/onthebalcony.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/onthebalcony.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/onthebalcony.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=30&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://onthebalcony.wordpress.com/2008/03/08/just-for-fun-map-as-higher-order-function-in-bash/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d1f2fc95154cef495bcbbde7d752f541?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">eelco</media:title>
		</media:content>
	</item>
		<item>
		<title>Beautiful timetables</title>
		<link>http://onthebalcony.wordpress.com/2007/11/11/beautiful-timetables/</link>
		<comments>http://onthebalcony.wordpress.com/2007/11/11/beautiful-timetables/#comments</comments>
		<pubDate>Sun, 11 Nov 2007 01:16:25 +0000</pubDate>
		<dc:creator>Eelco Lempsink</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://onthebalcony.wordpress.com/2007/11/11/beautiful-timetables/</guid>
		<description><![CDATA[Because I wanted a clear and compact way to display the timetable of the tram nearby, I created a small project. My goal was to have something more &#8216;visual&#8217; than a list with numbers. I am interested in new ways to display information and what&#8217;s nice about it and why. I think the result is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=29&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Because I wanted a clear and compact way to display the timetable of the tram nearby, I created a small project.  My goal was to have something more &#8216;visual&#8217; than a list with numbers.  I am interested in new ways to display information and what&#8217;s nice about it and why.</p>
<p><a HREF="http://eelco.slashpunt.org/timetable/tram-cs.pdf"><img ALT="Preview of output" SRC="http://eelco.slashpunt.org/timetable/timetable.png" /></a></p>
<p>I think the result is something that has a bit of a learning curve and is therefore less suitable for &#8216;one-time&#8217; usage.  On the other hand, because it&#8217;s more of a picture and not a bunch of numbers I think it&#8217;s much easier to learn the timetable by heart for regular users.</p>
<p>For specification I wanted a small and simple language and preferably not start with writing a parser, so I decided to hitch a ride with Haskell first.</p>
<p>I&#8217;d love to hear your opinion, both a first reaction and after experimenting with it.</p>
<p>» <strong><a HREF="http://eelco.slashpunt.org/timetable/timetable.zip">Download it</a></strong></p>
<p>(<a HREF="http://eelco.slashpunt.org/timetable/README.lhs">view readme</a> or <a HREF="http://eelco.slashpunt.org/timetable/timetable.hs">view haskell module</a>)</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/onthebalcony.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/onthebalcony.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/onthebalcony.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/onthebalcony.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/onthebalcony.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/onthebalcony.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/onthebalcony.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/onthebalcony.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/onthebalcony.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/onthebalcony.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/onthebalcony.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/onthebalcony.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/onthebalcony.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/onthebalcony.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/onthebalcony.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/onthebalcony.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=29&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://onthebalcony.wordpress.com/2007/11/11/beautiful-timetables/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d1f2fc95154cef495bcbbde7d752f541?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">eelco</media:title>
		</media:content>
	</item>
		<item>
		<title>A little puzzle</title>
		<link>http://onthebalcony.wordpress.com/2007/10/14/a-little-puzzle/</link>
		<comments>http://onthebalcony.wordpress.com/2007/10/14/a-little-puzzle/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 12:26:16 +0000</pubDate>
		<dc:creator>chriseidhof</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://onthebalcony.wordpress.com/2007/10/14/a-little-puzzle/</guid>
		<description><![CDATA[A couple of years ago, I learned about a fun little puzzle. The question is: what&#8217;s the next element in the following sequence: 1 1 1 2 1 1 2 1 1 1 1 1 2 2 1 Once I solved the puzzle, I wanted to see if I could come up with a short [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=28&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A couple of years ago, I learned about a fun little puzzle. The question is: what&#8217;s the next element in the following sequence:</p>
<p><code><br />
1<br />
1 1<br />
2 1<br />
1 2 1 1<br />
1 1 1 2 2 1<br />
</code></p>
<p>Once I solved the puzzle, I wanted to see if I could come up with a short function that generates this sequence. This is my haskell version:</p>
<p><code><br />
next [] = []<br />
next (x:xs) = [length start + 1,x] ++ next end<br />
  where (start, end) = span (== x) xs<br />
</code></p>
<p>You can call it like this:<br />
<code><br />
main = mapM (putStrLn . unwords . map show) (iterate next [1])<br />
</code></p>
<p>Update: <a href="http://martijn.van.steenbergen.nl/">Martijn</a> told me about some background behind this sequence. It&#8217;s called the <a href="http://mathworld.wolfram.com/LookandSaySequence.html">Look and Say Sequence</a>, and it&#8217;s a quite interesting sequence indeed.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/onthebalcony.wordpress.com/28/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/onthebalcony.wordpress.com/28/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/onthebalcony.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/onthebalcony.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/onthebalcony.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/onthebalcony.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/onthebalcony.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/onthebalcony.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/onthebalcony.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/onthebalcony.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/onthebalcony.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/onthebalcony.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/onthebalcony.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/onthebalcony.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/onthebalcony.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/onthebalcony.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=28&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://onthebalcony.wordpress.com/2007/10/14/a-little-puzzle/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ade0c334ecff1448bb96f5f733bf1f83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Chris Eidhof</media:title>
		</media:content>
	</item>
		<item>
		<title>Improving Vim&#8217;s Mac integration</title>
		<link>http://onthebalcony.wordpress.com/2007/07/17/improving-vims-mac-integration/</link>
		<comments>http://onthebalcony.wordpress.com/2007/07/17/improving-vims-mac-integration/#comments</comments>
		<pubDate>Tue, 17 Jul 2007 19:49:10 +0000</pubDate>
		<dc:creator>Eelco Lempsink</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://onthebalcony.wordpress.com/2007/07/17/improving-vims-mac-integration/</guid>
		<description><![CDATA[Update: our first patch is now available! Vim is a great editor and OS X a lovely operating system, but unfortunately, they do not go really well together.  No wonder requests for better OS X integration are at the top of the requested features list. But so far the Mac Vim community doesn&#8217;t seem to have the manpower to get cranking on these issues. Luckily there&#8217;s Jjgod Jiang working on a Summer Of Code [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=27&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Update: our first patch is <a HREF="http://wiki.macvim.org/wiki/VimPatches/ODBEditor">now available</a>!</strong></p>
<p>Vim is a great editor and OS X a lovely operating system, but unfortunately, they do not go really well together.  No wonder <a HREF="http://www.vim.org/sponsor/vote_results.php">requests for better OS X integration</a> are at the top of the requested features list.</p>
<p>But so far the Mac Vim community doesn&#8217;t seem to have the manpower to get cranking on these issues.  Luckily there&#8217;s <a HREF="http://code.google.com/p/vim-cocoa/">Jjgod Jiang working on a Summer Of Code project</a> to build a Cocoa GUI for vim.</p>
<p>As avid Vim users we&#8217;d like to contribute something as well.  So we took the week off and started hacking (with just a grain of C knowlegde and no prior Mac API experience) Vim to implement the <a HREF="http://www.barebones.com/support/develop/odbsuite.shtml">ODB Editor Suite</a> which will make it possible to use Vim from a whole bunch of FTP applications.  We&#8217;re making progress and hope to &#8216;release&#8217; a first version patch soon.</p>
<p>If time allows we&#8217;ll also try to develop a simple &#8216;Edit in Vim&#8217; button that can be used from text widgets in any application.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/onthebalcony.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/onthebalcony.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/onthebalcony.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/onthebalcony.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/onthebalcony.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/onthebalcony.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/onthebalcony.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/onthebalcony.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/onthebalcony.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/onthebalcony.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/onthebalcony.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/onthebalcony.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/onthebalcony.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/onthebalcony.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/onthebalcony.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/onthebalcony.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=27&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://onthebalcony.wordpress.com/2007/07/17/improving-vims-mac-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d1f2fc95154cef495bcbbde7d752f541?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">eelco</media:title>
		</media:content>
	</item>
		<item>
		<title>Mac OS X: Duplicate your Terminal-window in the same directory</title>
		<link>http://onthebalcony.wordpress.com/2007/06/11/mac-os-x-duplicate-your-terminal-window-in-the-same-directory/</link>
		<comments>http://onthebalcony.wordpress.com/2007/06/11/mac-os-x-duplicate-your-terminal-window-in-the-same-directory/#comments</comments>
		<pubDate>Mon, 11 Jun 2007 10:15:45 +0000</pubDate>
		<dc:creator>chriseidhof</dc:creator>
				<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://onthebalcony.wordpress.com/2007/06/11/mac-os-x-duplicate-your-terminal-window-in-the-same-directory/</guid>
		<description><![CDATA[I was looking for a way to duplicate the current Terminal-window in the same directory. I wrote a small script that does just this, save it as ~/bin/dup #!/bin/bash echo "cd `pwd`" &#62; ~/.bash_last_dir echo "rm ~/.bash_last_dir" &#62;&#62; ~/.bash_last_dir echo "touch ~/.bash_last_dir" &#62;&#62; ~/.bash_last_dir open -a Terminal . If you include the following line at [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=26&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was looking for a way to duplicate the current Terminal-window in the same directory. I wrote a<br />
small script that does just this, save it as ~/bin/dup</p>
<p><code><br />
#!/bin/bash<br />
echo "cd `pwd`" &gt; ~/.bash_last_dir<br />
echo "rm ~/.bash_last_dir" &gt;&gt; ~/.bash_last_dir<br />
echo "touch ~/.bash_last_dir" &gt;&gt; ~/.bash_last_dir<br />
open -a Terminal .<br />
</code></p>
<p>If you include the following line at the end of your ~/.bash_login, you&#8217;re all set:</p>
<p><code><br />
source ~/.bash_last_dir<br />
</code></p>
<p>Make sure the ~/bin directory is in your path, and type &#8220;dup&#8221; in your Terminal to duplicate it.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/onthebalcony.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/onthebalcony.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/onthebalcony.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/onthebalcony.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/onthebalcony.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/onthebalcony.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/onthebalcony.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/onthebalcony.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/onthebalcony.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/onthebalcony.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/onthebalcony.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/onthebalcony.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/onthebalcony.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/onthebalcony.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/onthebalcony.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/onthebalcony.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=26&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://onthebalcony.wordpress.com/2007/06/11/mac-os-x-duplicate-your-terminal-window-in-the-same-directory/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ade0c334ecff1448bb96f5f733bf1f83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Chris Eidhof</media:title>
		</media:content>
	</item>
		<item>
		<title>V: find and edit files quickly via your commandline</title>
		<link>http://onthebalcony.wordpress.com/2007/04/23/v-find-and-edit-files-quickly-via-your-commandline/</link>
		<comments>http://onthebalcony.wordpress.com/2007/04/23/v-find-and-edit-files-quickly-via-your-commandline/#comments</comments>
		<pubDate>Mon, 23 Apr 2007 01:46:12 +0000</pubDate>
		<dc:creator>chriseidhof</dc:creator>
				<category><![CDATA[Vim]]></category>

		<guid isPermaLink="false">http://onthebalcony.wordpress.com/2007/04/23/v-find-and-edit-files-quickly-via-your-commandline/</guid>
		<description><![CDATA[I&#8217;m working on a project with a lot of files. Most of the time, I know exactly which file I want to edit. However, because everything is nicely organized in directories and packages, it&#8217;s very tedious to keep typing a long file-path. I created a small tool which recursively searches for the (partial) filename you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=25&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project with a lot of files. Most of the time, I know exactly which file I want to edit. However, because everything is nicely organized in directories and packages, it&#8217;s very tedious to keep typing a long file-path.</p>
<p>I created a small tool which recursively searches for the (partial) filename you provide in the current directory. If it finds only one match, it will launch vim for that file. If it finds more matches, it will show you a list of files to choose from. It will remember your choice, and assign a weight to that file, so that it will bubble to the top of the list next time.</p>
<p>Currently the weight is assigned to the relative filepath. This means that you can easily switch to another branch of your project if it has the same structure. It also means that you always have to run the program from the root of your project.</p>
<p>As a small bonus I added a feature where you can specify the command to run. By default it is vim, but if you provide a different command as the second argument, it will launch that command. For example, you can run it as &#8220;v myfile less&#8221;, which will open the selected file in less instead of vim.</p>
<p>I hope you enjoy it, let me know if you do. Here&#8217;s the link: <a HREF="http://eidhof.nl/tech/v.rb">v.rb</a>. Save the file somewhere in your path.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/onthebalcony.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/onthebalcony.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/onthebalcony.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/onthebalcony.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/onthebalcony.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/onthebalcony.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/onthebalcony.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/onthebalcony.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/onthebalcony.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/onthebalcony.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/onthebalcony.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/onthebalcony.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/onthebalcony.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/onthebalcony.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/onthebalcony.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/onthebalcony.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=25&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://onthebalcony.wordpress.com/2007/04/23/v-find-and-edit-files-quickly-via-your-commandline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ade0c334ecff1448bb96f5f733bf1f83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Chris Eidhof</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby and elegance: Transpose</title>
		<link>http://onthebalcony.wordpress.com/2007/03/10/ruby-and-elegance-transpose/</link>
		<comments>http://onthebalcony.wordpress.com/2007/03/10/ruby-and-elegance-transpose/#comments</comments>
		<pubDate>Sat, 10 Mar 2007 15:15:23 +0000</pubDate>
		<dc:creator>benlenarts</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Shorties]]></category>

		<guid isPermaLink="false">http://onthebalcony.wordpress.com/2007/03/10/ruby-and-elegance-transpose/</guid>
		<description><![CDATA[I recently found that the Array class of Ruby has a zip method, which works much like Haskell&#8217;s zip function, except that it allows multiple arguments. For example: $ irb --simple-prompt &#62;&#62; [1,2,3].zip [4,5,6], [7,8,9] =&#62; [[1, 4, 7], [2, 5, 8], [3, 6, 9]] The night after I did this little experiment I suddenly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=23&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently found that the Array class of Ruby has a <a href="http://www.ruby-doc.org/core/classes/Array.html#M002248" title="RDoc documentation for the zip method">zip method</a>, which works much like Haskell&#8217;s <a href="http://undergraduate.csse.uwa.edu.au/units/230.301/lectureNotes/tourofprelude.html#zip" title="Definition of Haskell's zip function">zip function</a>, except that it allows multiple arguments.</p>
<p>For example:<br />
<code><br />
$ irb --simple-prompt<br />
&gt;&gt; [1,2,3].zip [4,5,6], [7,8,9]<br />
=&gt; [[1, 4, 7], [2, 5, 8], [3, 6, 9]]<br />
</code></p>
<p>The night after I did this little experiment I suddenly realized: this is a transpose function! I quickly got out of bed to document my little discovery:</p>
<p><code><br />
def transpose(matrix)<br />
matrix[0].zip *matrix[1..-1]<br />
end<br />
</code></p>
<p>It&#8217;s the little things that make me like this language so much.</p>
<p>Update: I forgot the asterisk before <code>matrix[1..-1]</code> in the above method.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/onthebalcony.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/onthebalcony.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/onthebalcony.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/onthebalcony.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/onthebalcony.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/onthebalcony.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/onthebalcony.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/onthebalcony.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/onthebalcony.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/onthebalcony.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/onthebalcony.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/onthebalcony.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/onthebalcony.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/onthebalcony.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/onthebalcony.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/onthebalcony.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=23&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://onthebalcony.wordpress.com/2007/03/10/ruby-and-elegance-transpose/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/adab71f7de508a8d844338d390e97a99?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">benlenarts</media:title>
		</media:content>
	</item>
		<item>
		<title>Summing it up</title>
		<link>http://onthebalcony.wordpress.com/2007/02/24/summing-it-up/</link>
		<comments>http://onthebalcony.wordpress.com/2007/02/24/summing-it-up/#comments</comments>
		<pubDate>Sat, 24 Feb 2007 05:35:36 +0000</pubDate>
		<dc:creator>chriseidhof</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Shorties]]></category>

		<guid isPermaLink="false">http://onthebalcony.wordpress.com/2007/02/24/summing-it-up/</guid>
		<description><![CDATA[Today, I had a list of integers, and I wanted to sum it up. I guessed that I should write a script in Ruby, to make sure it would get done within 2 minutes. So I fired up my editor, and wrote the following script: sum = 0 ; $stdin.each do &#124;line&#124; sum+=line.to_i end puts [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=22&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today, I had a list of integers, and I wanted to sum it up. I guessed that I should write a script in Ruby, to make sure it would get done within 2 minutes. So I fired up my editor, and wrote the following script:</p>
<p><code>sum = 0 ;<br />
$stdin.each do |line|<br />
sum+=line.to_i<br />
end<br />
puts sum<br />
</code></p>
<p>Pretty straightforward. I&#8217;d rather had written the script in Haskell, but I figured I needed to get things done. This evening I tried the same thing in Haskell, but to I was surprised: it was even quicker and more straightforward than the Ruby version! Here it is:</p>
<p><code>main = interact $ show . sum . map read . lines<br />
</code></p>
<p>If you&#8217;d like more of these tiny tools, see <a HREF="http://www.cse.unsw.edu.au/~dons/data/Basics.html">Haskell Unix Tools</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/onthebalcony.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/onthebalcony.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/onthebalcony.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/onthebalcony.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/onthebalcony.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/onthebalcony.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/onthebalcony.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/onthebalcony.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/onthebalcony.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/onthebalcony.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/onthebalcony.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/onthebalcony.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/onthebalcony.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/onthebalcony.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/onthebalcony.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/onthebalcony.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=22&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://onthebalcony.wordpress.com/2007/02/24/summing-it-up/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ade0c334ecff1448bb96f5f733bf1f83?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Chris Eidhof</media:title>
		</media:content>
	</item>
		<item>
		<title>My Evolution as a Haskell Programmer: Factorial with Arrows</title>
		<link>http://onthebalcony.wordpress.com/2007/02/19/my-evolution-as-a-haskell-programmer/</link>
		<comments>http://onthebalcony.wordpress.com/2007/02/19/my-evolution-as-a-haskell-programmer/#comments</comments>
		<pubDate>Mon, 19 Feb 2007 17:18:51 +0000</pubDate>
		<dc:creator>Eelco Lempsink</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://onthebalcony.wordpress.com/2007/02/19/my-evolution-as-a-haskell-programmer/</guid>
		<description><![CDATA[A couple of years ago Fritz Ruehr wrote a great article about The Evolution of a Haskell Programmer. It was written in 2001, when I was still in high school, some years away from being introduced to the beautiful Haskell programming language. Currently, I&#8217;m following a course on Advanced Functional Programming at the Utrecht University. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=20&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A couple of years ago Fritz Ruehr wrote a great article about <a HREF="http://www.willamette.edu/~fruehr/haskell/evolution.html">The Evolution of a Haskell Programmer</a>.  It was written in 2001, when I was still in high school, some years away from being introduced to the beautiful Haskell programming language.</p>
<p>Currently, I&#8217;m following a course on <a HREF="http://www.cs.uu.nl/wiki/Afp/WebHome">Advanced Functional Programming</a> at the Utrecht University.  One of the advanced topics tought in that course is about <a HREF="http://www.haskell.org/arrows/">Arrows</a>.  Arrows are an abstraction of computations, just like Monads, but even more general and pretty nice to define stream functions with (useful for defining logical circuits, for example). I&#8217;m still trying to get my head fully around it, but so far I understand it enough to add a new part to the evolution (a missing link!): the factorial function defined with arrows.</p>
<p>I will present the code below and sparsely comment on it.  Most of the code is actually from the Advanced Functional Programming lecture.</p>
<pre>
-- We need this library
import Control.Arrow        

-- Define a type for stream functions, from one list to another
newtype SF a b = SF { runSF :: [a] -&gt; [b] }      

-- Define the Arrow functions for the SF type.  Once you've
-- defined these three, you'll get a lot of other functions for
-- free.
instance Arrow SF where
  arr f = SF (map f)
  SF f &gt;&gt;&gt; SF g = SF (f &gt;&gt;&gt; g)
  first (SF f) = SF (unzip &gt;&gt;&gt; first f &gt;&gt;&gt; uncurry zip)      

-- arr   lifts a function to the arrow domain
-- &gt;&gt;&gt;   combines (connects) two arrow functions
-- first only applies the function to the first part from a
--       tuple      

-- See the http://www.haskell.org/arrows for more
-- information and some nice graphics, which will help
-- understanding.</pre>
<p>Okay, so far, so good.  By defining the &#8216;first&#8217; and &#8216;&gt;&gt;&gt;&#8217; functions, we get an &#8216;&amp;&amp;&amp;&#8217; combinator for free, which we will use in our final definition.  For example: &#8216;f &amp;&amp;&amp; g&#8217; can be understood as accepting and input x, then applying <strong>both</strong> f and g to it, resulting in the output of a tuple of the results.  In short, the type of &#8216;&amp;&amp;&amp;&#8217; is &#8216;Arrow arr =&gt; arr a b -&gt; arr a c -&gt; arr a (b, c)&#8217;.</p>
<pre>
-- The type of loop is (ArrowLoop arr) =&gt; arr (a, c) (b, c) -&gt;
-- arr a b.  A loop makes a function from 'a' to 'b', while
-- 'looping' a 'c'.
instance ArrowLoop SF where
  loop (SF f) = SF $ \\as -&gt;
    let (bs,cs) = unzip (f (zip as (stream cs)))
    in bs      

-- Note in the definition that cs is defined recursive(!)  This
-- is really where the usefulness of Haskell's lazyness kicks
-- in.  Although, because zip and unzip are both strict, we
-- have to help it a little, by defining a helper function
-- stream.      

stream :: [a] -&gt; [a]
stream ~(x:xs) = x:stream xs      

-- The ~ in the pattern makes the pattern matching irrefutable,
-- which means that the pattern will not be interpreted but
-- assumed to be correct.</pre>
<p>Well, with that out of the way we can get to the good stuff.  We just need two simple helpers to modify the stream.</p>
<pre>
-- 'Delays' a stream by prepending an element.  This can be
-- used to initialize a stream _before_ the input is read.
-- We're going to need this to use that nasty loop above.
-- Remember, the c was defined recursive, without
-- initialization.
delay :: a -&gt; SF a a
delay x = SF (x:)      

-- Takes an input and muliplies it.  It 'simply' lifts an
-- uncurried (*) to the arrow domain.
-- Example (try it yourself): mul (6,7) = 42
mul :: Arrow arr =&gt; arr (Integer, Integer) Integer
mul = arr (uncurry (*))</pre>
<p>Okay, now, the basic idea is to supply a stream function with the list of integers and then all we have to do is multiply the result of the first item with the second and multiply that result with the third, etc.  Aha, that&#8217;s easy, we can just use the loop for that.  The only thing we need is in initialization value to start the multiplying with.  For this we use the delay.  Schematicly, our plan looks like the following picture.</p>
<p><img SRC="http://onthebalcony.files.wordpress.com/2007/02/fac.png?w=450" ALT="Factorial Arrows" /></p>
<p>You can clearly see how the loop works while the input and the output of the whole is still a single stream.  The dot in the image where the output of &#8216;mul&#8217; splits is actually the &#8216;&amp;&amp;&amp;&#8217; combinator.  The code then looks like this.</p>
<pre>
facSF :: SF Integer Integer
facSF = loop (mul &gt;&gt;&gt; (arr id &amp;&amp;&amp; delay 1))</pre>
<p>Pretty clean, eh?  Only thing left is a nice wrapper to run this thing.</p>
<pre>
-- Using Integers so that for large numbers (and factorials
-- tend to get really large fast) it still produces nice
-- output.  Try 'fac 420' for example.
fac :: Integer -&gt; Integer
fac x = runSF facSF [1..x] !! fromInteger (x - 1)</pre>
<p>This concludes our fun with Arrows.  Viva la evolucion!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/onthebalcony.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/onthebalcony.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/onthebalcony.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/onthebalcony.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/onthebalcony.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/onthebalcony.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/onthebalcony.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/onthebalcony.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/onthebalcony.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/onthebalcony.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/onthebalcony.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/onthebalcony.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/onthebalcony.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/onthebalcony.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/onthebalcony.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/onthebalcony.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=onthebalcony.wordpress.com&amp;blog=324375&amp;post=20&amp;subd=onthebalcony&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://onthebalcony.wordpress.com/2007/02/19/my-evolution-as-a-haskell-programmer/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d1f2fc95154cef495bcbbde7d752f541?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">eelco</media:title>
		</media:content>
	</item>
	</channel>
</rss>
