<?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>Ryan's Tech Blog &#187; clojure</title>
	<atom:link href="http://ryepup.unwashedmeme.com/blog/category/clojure/feed/" rel="self" type="application/rss+xml" />
	<link>http://ryepup.unwashedmeme.com/blog</link>
	<description>mostly tech, mostly rants</description>
	<lastBuildDate>Wed, 04 Jan 2012 03:42:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Brian&#8217;s functional brain in lisp</title>
		<link>http://ryepup.unwashedmeme.com/blog/2009/10/04/brians-functional-brain-in-lisp/</link>
		<comments>http://ryepup.unwashedmeme.com/blog/2009/10/04/brians-functional-brain-in-lisp/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 03:47:19 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[cellular automata]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://ryepup.unwashedmeme.com/blog/?p=135</guid>
		<description><![CDATA[Last week I saw a breathless headline on proggit about clojure and Brian&#8217;s functional brain: http://blog.bestinclass.dk/index.php/2009/10/brians-functional-brain/, written by Lau. As a Common Lisp programmer, Clojure irritates me for various irrational reasons.  As an exercise in breaking those down, I ported Lau&#8217;s 67 line program (which had no comments) to CL running on SBCL using asdf-installable [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I saw a breathless headline on proggit about clojure and Brian&#8217;s functional brain: <a href="http://blog.bestinclass.dk/index.php/2009/10/brians-functional-brain/">http://blog.bestinclass.dk/index.php/2009/10/brians-functional-brain/</a>, written by Lau.</p>
<p>As a Common Lisp programmer, Clojure irritates me for various irrational reasons.  As an exercise in breaking those down, I ported Lau&#8217;s 67 line program (which had no comments) to CL running on SBCL using asdf-installable libraries.  I used <a href="http://code.google.com/p/lispbuilder/">lispbuilders-sdl</a> for display and <a href="http://marijn.haverbeke.nl/pcall/">pcall</a> for concurrency.  I ended up with 115 lines, including comments and some significant differences in the program.</p>
<p>I went through a few revisions, initially trying to transliterate the code, looking at the fine clojure API docs to figure out what different things did.  Then I gave up on that wrote more idiomatic (at least for me) lisp, but still resisted the urge to use iterate of alexandria.  I wanted to have code that was as close to the bare language as possible, so I could make an apples-to-apples comparison.  Now that the exercise is done, I think that goal was unattainable.  It&#8217;s close, but the differences in the languages are significant, so it&#8217;s not an great comparison.</p>
<p>After the first round, I started diverging more from the Lau&#8217;s version, looking for higher FPS and nicer lisp.  I ended up with a few major differences:</p>
<ol>
<li>I used a 2D array to represent the world, the Lau used a single long vector and I didn&#8217;t quite understand how it was determining adjacency</li>
<li>I had a lot more functions to abstract out that data structure choice (ie: instead of calling aref everywhere, I made a get-cell function)</li>
<li>Lau called pmap function to calculate each cell&#8217;s next value in parallel, and I used pcall to calculate the next whole world state while the main thread rendered.</li>
<li>Lau drew boxes for each rendering loop, I made two SDL surfaces up front and blitted them in at the right spots</li>
</ol>
<p>I spent a little under 4 hours playing with it, and a lot of that was reading documentation.  I don&#8217;t think any conclusions can be made from this for a &#8220;common lisp vs clojure&#8221; flame war, these are both fairly throw-away pieces of code.  I have no doubt that any experiences lisper or clojurer would find a lot of obvious improvements.</p>
<p>Some of my observations along the way:</p>
<ol>
<li>getting the lisp libraries to work (which I&#8217;ve done in the past) is probably harder than getting clojure working and using java libs.</li>
<li>java libs look like a pain in the ass.  This softens the &#8220;and you can use java libs!&#8221; selling point of clojure for me.  They&#8217;re still java libs.</li>
<li>The places where clojure calls java are kinda ugly, it&#8217;s a square peg in a round hole.</li>
<li>clojure has a ton of lazy-evaluation semantics built into the language.  In this case, that seemed to be a bad thing, and most of Lau&#8217;s code was calling some wrapper function to say &#8220;no really, I want you to actually do this&#8221;.</li>
<li>Clojure has more syntax than I thought, using # % [ ] _ to mean different things (maybe in different contexts?).</li>
<li>I&#8217;m not sure how the STM features I&#8217;ve heard a lot about come into play here, if at all.</li>
<li>I should be asdf loading my libs in a nicer way, right now you need to evaluate those first lines, and then compile the file.  I didn&#8217;t have the motivation to create an .asd file or finally learn how to use eval-when properly.</li>
<li>I like long, descriptive function names.  Some of the ones from clojure irriated me: doall, doto.  It reminds me of arc a little.</li>
<li>I was confused by the per-cell parallelism in the clojure version (I think clojure uses native threads in a threadpool).  Pcall does the same thing, but I figured I&#8217;d be spending more time context switching than calculating, and it was getting late.</li>
</ol>
<p>Anyhoo, a fun sunday evening.</p>
<p>Code is on github: <a href="http://github.com/ryepup/sandbox/blob/master/brain.lisp">http://github.com/ryepup/sandbox/blob/master/brain.lisp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ryepup.unwashedmeme.com/blog/2009/10/04/brians-functional-brain-in-lisp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.545 seconds -->

