<?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>Foognostic blogs &#187; lisp</title>
	<atom:link href="http://blogs.foognostic.net/topics/code/lisp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.foognostic.net</link>
	<description>Seeking knowledge of foo</description>
	<lastBuildDate>Fri, 23 Apr 2010 12:45:34 +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>Reduce your way into good Clojure</title>
		<link>http://blogs.foognostic.net/2009/06/reduce-your-way-into-good-clojure/</link>
		<comments>http://blogs.foognostic.net/2009/06/reduce-your-way-into-good-clojure/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 00:17:33 +0000</pubDate>
		<dc:creator>Seth Schroeder</dc:creator>
				<category><![CDATA[clojure]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://blogs.foognostic.net/?p=134</guid>
		<description><![CDATA[In my previous <a href="http://blogs.foognostic.net/2009/06/put-that-for-loop-down/">post</a> I discussed replacing for loops with the <code>(map)</code> function. That works, until it doesn't.]]></description>
			<content:encoded><![CDATA[<p>Standard disclaimer: <a href="http://blogs.foognostic.net/disclaimer-clojure-is-a-new-hobby/">Clojure is a new hobby.</a></p>

<p>In my previous <a href="http://blogs.foognostic.net/2009/06/put-that-for-loop-down/">post</a> I discussed replacing for loops with the <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span><span style="color: #66cc66;">&#41;</span></span></code> function. That works, until it doesn't.</p>

<p>Another step needed to generate the cosine similarity for two strings is to create a frequency histogram, or how many times each character pair occurs in a string. This is a pretty good fit for a hash map, where the keys are the character pairs, and the values the occurrences.</p>

<p>Here was my initial try. This code meant to do well... but went far, far away from where I wanted. Let's take a detailed look at my failings:</p>

<div class="codecolorer-container clojure vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="clojure codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">user=&gt; <br />
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#91;</span>hm <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">hash-map</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">fn</span> <span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">key</span> <span style="color: #b1b100;">val</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">assoc</span> hm <span style="color: #b1b100;">key</span> <span style="color: #b1b100;">val</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;a&quot;</span> <span style="color: #ff0000;">&quot;b&quot;</span> <span style="color: #ff0000;">&quot;a&quot;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>

<p>What I wanted: a map like this => <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;b&quot;</span> <span style="color: #cc66cc;">2</span>, <span style="color: #ff0000;">&quot;a&quot;</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#125;</span></span></code>. What I <b>got</b> was three hash maps, each with one key/value pair => <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;a&quot;</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;b&quot;</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;a&quot;</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span></span></code>. The intent was to use <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #b1b100;">map</span></span></code> to iterate over the sequences, and use <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #b1b100;">assoc</span></span></code> to put the key and value into one hash map. And now, for the parade of errors...</p>

<ol>
<li>Use the <a href="http://clojure.org/api#zipmap">zipmap</a> function to build hashmaps like this: <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">zipmap</span> <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;a&quot;</span> <span style="color: #ff0000;">&quot;b&quot;</span> <span style="color: #ff0000;">&quot;a&quot;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">2</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span></span></code> => <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;b&quot;</span> <span style="color: #cc66cc;">2</span>, <span style="color: #ff0000;">&quot;a&quot;</span> <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#125;</span></span></code>
<li>Variables in the let block cannot be changed...
<li>... but I really needed to update the hash map defined in the let block.
</ol>

<p>Rather than continue to stew uselessly I used Emacs to hop into the <a href="irc://irc.freenode.net/#clojure">#clojure IRC</a> channel. A wonderful person suggested the <a href="http://clojure.org/api#reduce"><code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #b1b100;">reduce</span></span></code></a> function; I'd used it once in Ruby where it is best known as <a href="http://railspikes.com/2008/8/11/understanding-map-and-reduce">inject</a>. I'm going to skimp on my description of reduce a little since that article is <b>so</b> well done.</p>

<p><code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #b1b100;">reduce</span></span></code> iterates over a collection like <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #b1b100;">map</span></span></code>, but it passes a mutable context to each callback. The return value of <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #b1b100;">reduce</span></span></code> is the final value of the context... essentially. I am still coming up to speed on it obviously.</p>

<p>Anyhow, enough yammering. Here is <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #b1b100;">reduce</span></span></code> in action:</p>

<div class="codecolorer-container clojure vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="clojure codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defn</span> dot-product <span style="color: #66cc66;">&#91;</span>l_histo r_histo<span style="color: #66cc66;">&#93;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">reduce</span><br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">fn</span> <span style="color: #66cc66;">&#91;</span>product <span style="color: #b1b100;">key</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span>+ product<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>* <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">get</span> l_histo <span style="color: #b1b100;">key</span> 0<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">get</span> r_histo <span style="color: #b1b100;">key</span> 0<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp;0<br />
&nbsp; &nbsp;<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">keys</span> l_histo<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>

<p>Key points:</p>

<ul>
<li><code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#91;</span>l_histo r_histo<span style="color: #66cc66;">&#93;</span></span></code> -- these are the arguments to the dot-product function.
<li><code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">fn</span></span></code> defines an anonymous function.
<li><code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">get</span></span></code> gets the value for the specified key from the specified map, returning the final argument when the key is absent.
<li><code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #cc66cc;">0</span></span></code> is the default value for <code class="codecolorer clojure dawn"><span class="clojure">product</span></code>
<li><code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">keys</span></span></code> returns the keys of the specified hash map
<li>Clojure really wins a lot by delegating to Java. This happened for free: <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#40;</span>Math/sqrt <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span></span></code> => <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #cc66cc;">10.0</span></span></code>
</ul>

<p>So, reduce is a critical step for people coming from imperative programming languages looking to do basic things with collections.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.foognostic.net/2009/06/reduce-your-way-into-good-clojure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Put that for loop down</title>
		<link>http://blogs.foognostic.net/2009/06/put-that-for-loop-down/</link>
		<comments>http://blogs.foognostic.net/2009/06/put-that-for-loop-down/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 19:22:49 +0000</pubDate>
		<dc:creator>Seth Schroeder</dc:creator>
				<category><![CDATA[clojure]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://blogs.foognostic.net/?p=124</guid>
		<description><![CDATA[Standard disclaimer: Clojure is a new hobby. I've been spending a lot of time with Clojure recently to prepare for the ICFP 2009 contest. It hasn't been the easiest thing, but the difficulty has come from trying to grasp many new concepts at once. The documentation has been pretty good, and the IRC channel has [...]]]></description>
			<content:encoded><![CDATA[<p>Standard disclaimer: <a href="http://blogs.foognostic.net/disclaimer-clojure-is-a-new-hobby/">Clojure is a new hobby.</a></p>

<p>I've been spending a lot of time with Clojure recently to prepare for the ICFP 2009 contest. It hasn't been the easiest thing, but the difficulty has come from trying to grasp many new concepts at once. The documentation has been pretty good, and the IRC channel has been pretty worthwhile.</p>

<p>I'm trying to settle on a specific task to accomplish when learning a new language. Something concrete but still a little academic... implementing cosine similarity using character bigrams isn't much code, but it covers enough bases to be useful.</p>

<p>Part of the process involves splitting a string into overlapping character pairs.</p>

<p>Bad old me instinctively thinks "for loop".</p>

<p>Good new me thinks... bad old me probably has it right. But it doesn't feel very Clojure-y. This solution is a little more Clojuriffic, probably still a long shot from idiomatic:</p>

<div class="codecolorer-container clojure vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="clojure codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defn</span> split-bigrams <span style="color: #66cc66;">&#91;</span>text<span style="color: #66cc66;">&#93;</span><br />
&nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span> <br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">fn</span> <span style="color: #66cc66;">&#91;</span>l r<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">str</span> l r<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">seq</span> text<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">rest</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">seq</span> text<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></div></div>

<p>Bad old me (BOM) would have iterated over the string using a for loop with an index variable, cycling length - 1 times.</p>

<p>Good new me (GNM) had to take a different approach. I converted the string into two sequences; the first was just the string, but the second was the string minus the first character.</p>

<div class="codecolorer-container clojure vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="clojure codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sequence A : <span style="color: #66cc66;">&#91;</span>A B C D E F<span style="color: #66cc66;">&#93;</span><br />
sequence A': <span style="color: #66cc66;">&#91;</span>B C D E F<span style="color: #66cc66;">&#93;</span></div></div>

<p>The <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span><span style="color: #66cc66;">&#41;</span></span></code> function takes a callback and a number of sequences. The callback function gets the nth element from each sequence, and the output from the callback is collected and returned by <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span><span style="color: #66cc66;">&#41;</span></span></code>. I don't have to specify a length or repetition count, as <code class="codecolorer clojure dawn"><span class="clojure"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">map</span><span style="color: #66cc66;">&#41;</span></span></code> stops processing when any of the collections run out of data.</p>

<div class="codecolorer-container clojure vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="clojure codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">user=&gt; <span style="color: #66cc66;">&#40;</span>split-bigrams <span style="color: #ff0000;">&quot;ABCDEF&quot;</span><span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp; <br />
<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;AB&quot;</span> <span style="color: #ff0000;">&quot;BC&quot;</span> <span style="color: #ff0000;">&quot;CD&quot;</span> <span style="color: #ff0000;">&quot;DE&quot;</span> <span style="color: #ff0000;">&quot;EF&quot;</span><span style="color: #66cc66;">&#41;</span></div></div>

<p>This hasn't taken a lot of time, but more than I like. It has taken <b>A LOT</b> of patience, energy, and focus during that time. But I like finding new ways to solve problems. Now I have a new tool in my nerdbelt, one that pushes the for loop back a little bit.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.foognostic.net/2009/06/put-that-for-loop-down/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring projects in org mode, or defining variables in Lisp is strange</title>
		<link>http://blogs.foognostic.net/2009/04/configuring-projects-in-org-mode-or-defining-variables-in-lisp-is-strange/</link>
		<comments>http://blogs.foognostic.net/2009/04/configuring-projects-in-org-mode-or-defining-variables-in-lisp-is-strange/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 23:06:54 +0000</pubDate>
		<dc:creator>Seth Schroeder</dc:creator>
				<category><![CDATA[gnu]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[org-mode]]></category>

		<guid isPermaLink="false">http://blogs.foognostic.net/?p=92</guid>
		<description><![CDATA[Org mode in GNU Emacs makes it somewhat easy to publish its files as a small static website. You define the files to publish, how to convert them, where to publish them, and so on. The bad news is that you need to manually write a big data structure in Emacs Lisp. Not what a Lisp newbie really wanted to hear (no customize page?) but I decided org mode was worth the pain. Speaking of pain, here's the data structure:]]></description>
			<content:encoded><![CDATA[<p><a href="http://orgmode.org">Org mode</a> in <a href="http://directory.fsf.org/project/emacs/">GNU Emacs</a> makes it somewhat easy to publish its files as a small static website. You define the files to publish, how to convert them, where to publish them, and so on. The bad news is that you need to manually write a big data structure in Emacs Lisp. Not what a Lisp newbie really wanted to hear (no customize page?) but I decided org mode was worth the pain. Speaking of pain, here's the data structure:</p>

<p><pre class="">
<a name="cfg_loc_0"> 0:</a>  (set
<a name="cfg_loc_1"> 1:</a>    (quote org-publish-project-alist)
<a name="cfg_loc_2"> 2:</a>    '
<a name="cfg_loc_3"> 3:</a>    (
<a name="cfg_loc_4"> 4:</a>      (
<a name="cfg_loc_5"> 5:</a>        &quot;tsn&quot;
<a name="cfg_loc_6"> 6:</a>        :base-directory &quot;~/Documents/foog/tsn&quot;
<a name="cfg_loc_7"> 7:</a>        :base-extension &quot;org&quot;
<a name="cfg_loc_8"> 8:</a>         :publishing-directory &quot;/dev/null&quot;
<a name="cfg_loc_9"> 9:</a>         :publishing-function org-publish-org-to-html
<a name="cfg_loc_10">10:</a>      )
<a name="cfg_loc_11">11:</a>    )
<a name="cfg_loc_12">12:</a>  )
</pre></p>

<p>All that work just to define a list of lists? I could just write it in Ruby as:</p>

<p><pre>
 # pretend this function exists in Ruby
 # def org_publish_to_html() end
org_publish_project_alist = [
    [ &quot;tsn&quot;,
      :base_directory, &quot;~/Documents/foog/tsn&quot;,
      :base_extension, &quot;org&quot;,
      :publishing_directory, &quot;~/Documents/foog/tsn_export&quot;,
      :publishing_function, org_publish_to_html ]
];
</pre></p>

<p>The major difference is all this

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">set</div></div>

and

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">quote</div></div>

nonsense. How many function calls does it take to initialize a variable in Lisp?? It turned out that answering that question well required some spelunking into Lisp. It kind of makes me appreciate GNU Emacs Lisp as a low-level high-level language.</p>

<h3>And now, we plunge through the rabbit hole!</h3>

<p>So, why call the

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">(quote)</div></div>

function when defining a variable? I didn't realize what a good question this was. The answer means paying close attention to references and values. Let's take a quick look at a function which determines whether its argument is a value or a reference:</p>

<p><pre>
(symbolp 123)           =&gt; nil  ;; nil is false in Emacs Lisp
(symbolp (quote 123))   =&gt; nil  ;; 123 passes through...
(symbolp (quote &quot;abc&quot;)) =&gt; nil  ;; abc passes through
(symbolp (quote foo))   =&gt; t    ;; but foo is a symbol.
</pre></p>

<p>Okay, so now we can distinguish between a value and a reference. The next step is assigning a value to a reference. This is where

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">(quote)</div></div>

is essential.</p>

<p><pre>
(set foo 123) =&gt; Lisp error: (void-variable foo)
</pre></p>

<p>That silly Lisp interpreter, trying to get a value while we are in the middle of setting it. That's where

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">(quote)</div></div>

comes in. The function call to quote is evaluated, and the result is passed as the first argument to

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">(set)</div></div>

. That makes some sense, but because variable definition happens <b>ALL THE TIME</b> in imperative programming languages Emacs Lisp has tried to make this as easy as possible:</p>

<p><pre>
(set (quote foo) 123)  =&gt; 123  ;; No one does this
(set 'foo 456)         =&gt; 456  ;; 'foo = (quote foo)
(setq foo 789)         =&gt; 789  ;; People do this one.
</pre></p>

<h2>INTERMISSION</h2>

<p>Now that variable assignment has been hashed out we can pick up speed a bit and finish this off:</p>

<p><ul>
<li><a href="#cfg_loc_1">Line 1</a> specifies the symbol we want to use.
<li><a href="#cfg_loc_2">Line 2</a> is just a macro for

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">(quote)</div></div>

, so the contents will be returned without being evaluated.
<li><a href="#cfg_loc_3">Line 3</a> starts a list. To me this implies that the variable

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">org-publish-project-alist</div></div>

will contain an array of ... well, not sure yet.
<li><a href="#cfg_loc_4">Line 4</a> starts a list. This list will be the first item in the list defined by

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">org-publish-project-alist</div></div>

.
<li><a href="#cfg_loc_5">Line 5</a> is just a string. It is the first element in the list. Calling

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">(car)</div></div>

on the list started at line 4 would return &quot;tsn&quot;.
<li><a href="#cfg_loc_6">Line 6</a> contains the 2nd and 3rd items in the list.

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">:base-directory</div></div>

is a keyword symbol (

<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">(symbolp :base-directory) =&amp;gt; t</div></div>

). &quot;~/Documents/foog/tsn&quot; is the next element in the list.
<li>Lines 7-9 define the remnant of the list started at line 4.
<li>The remaining lines are the obligatory closing parens.
</ul>
</p>

<p>Probably because I am very new to Lisp I don't understand why flat lists are used to store this data. Key value pairs are a great fit for hash maps or associative lists (the variable name ends with alist...). My first attempt to restructure the data would be:</p>

<p><pre>
(setq org-projects
  '(
     ("tsn"
       (:base-directory . "~/Documents/foog/tsn")
       (:base-extension . "org")
       (:publishing-directory . "~/Documents/foog/tsn_export")
       (:publishing-function . org-publish-org-to-html))
     ("css" 
       (:base-directory . "~/Documents/foog/tsn/css")
       (:base-extension . "css"))
     ("img" 
       (:base-directory . "~/Documents/foog/tsn/images")
       (:base-extension . "jpg|png"))
  ))
</pre></p>

<p>The difference being that key value pairs are stored in an associative list. This lets you take advantage of built in functions for getting property values.</p>

<p><pre>
(mapcar
  (lambda (elt)
    (let
      ((project (car elt))
       (properties (cdr elt)))
      (print (format "Project %s has base extension %s"
                      project
                      (cdr (assoc :base-extension properties))))))
  org-projects)
</pre></p>

<p>Output:
("Project tsn has base extension org" "Project css has base extension css" "Project img has base extension jpg|png")</p>

<p>Wow, look at all the rambling. At least now I understand how to manually configure org mode's projects.</p>

<p>Lisp is neat.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.foognostic.net/2009/04/configuring-projects-in-org-mode-or-defining-variables-in-lisp-is-strange/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
