<?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>sinistral.sourcery &#187; Code</title>
	<atom:link href="http://tierseven.net/denizens/marc/blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://tierseven.net/denizens/marc/blog</link>
	<description>bug bait</description>
	<lastBuildDate>Mon, 28 Dec 2009 08:41:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>regular expression matching without a state machine</title>
		<link>http://tierseven.net/denizens/marc/blog/2009/08/05/regular-expression-matching-without-a-state-machine/</link>
		<comments>http://tierseven.net/denizens/marc/blog/2009/08/05/regular-expression-matching-without-a-state-machine/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 06:03:34 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://tierseven.net/denizens/marc/blog/?p=114</guid>
		<description><![CDATA[Over the past few days I&#8217;ve been brushing up on my compiler theory, and in the course of my readings happened across an interesting article in the Scala blogs.  The author presented a very concise (albeit not complete; see the comments following the article) implementation of a regex matching engine.  I was intrigued [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past few days I&#8217;ve been brushing up on my compiler theory, and in the course of my readings happened across an <a href="http://scala-blogs.org/2007/12/regexp-but-no-state-machine.html">interesting article</a> in the Scala blogs.  The author presented a very concise (albeit not complete; see the comments following the article) implementation of a regex matching engine.  I was intrigued and thought I&#8217;d try my hand at writing it in Common Lisp.  My naive implementation:</p>
<pre>
(defclass&nbsp;regex&nbsp;()&nbsp;())

(defclass&nbsp;phi&nbsp;(regex)&nbsp;())

(defclass&nbsp;empty&nbsp;(regex)&nbsp;())

(defclass&nbsp;l&nbsp;(regex)&nbsp;((letter&nbsp;:initarg&nbsp;:letter)))

(defclass&nbsp;choice&nbsp;(regex)
&nbsp;&nbsp;((left&nbsp;:initarg&nbsp;:left)
&nbsp;&nbsp;&nbsp;(right&nbsp;:initarg&nbsp;:right)))

(defclass&nbsp;seq&nbsp;(regex)
&nbsp;&nbsp;((left&nbsp;:initarg&nbsp;:left)
&nbsp;&nbsp;&nbsp;(right&nbsp;:initarg&nbsp;:right)))

(defclass&nbsp;star&nbsp;(regex)&nbsp;((expr&nbsp;:initarg&nbsp;:exp)))

(defgeneric&nbsp;accepts-empty&nbsp;(re))

(defmethod&nbsp;accepts-empty&nbsp;((re&nbsp;phi))&nbsp;nil)

(defmethod&nbsp;accepts-empty&nbsp;((re&nbsp;empty))&nbsp;t)

(defmethod&nbsp;accepts-empty&nbsp;((re&nbsp;choice))
&nbsp;&nbsp;(or&nbsp;(accepts-empty&nbsp;(slot-value&nbsp;re&nbsp;'left))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(accepts-empty&nbsp;(slot-value&nbsp;re&nbsp;'right))))

(defmethod&nbsp;accepts-empty&nbsp;((re&nbsp;seq))
&nbsp;&nbsp;(and&nbsp;(accepts-empty&nbsp;(slot-value&nbsp;re&nbsp;'left))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(accepts-empty&nbsp;(slot-value&nbsp;re&nbsp;'right))))

(defmethod&nbsp;accepts-empty&nbsp;((re&nbsp;star))&nbsp;t)

(defmethod&nbsp;accepts-empty&nbsp;((re&nbsp;l))&nbsp;nil)

(defgeneric&nbsp;part-deriv&nbsp;(regex&nbsp;item))

(defmethod&nbsp;part-deriv&nbsp;((re&nbsp;phi)&nbsp;atom)
&nbsp;&nbsp;(make-instance&nbsp;'phi))

(defmethod&nbsp;part-deriv&nbsp;((re&nbsp;empty)&nbsp;atom)
&nbsp;&nbsp;(make-instance&nbsp;'phi))

(defmethod&nbsp;part-deriv&nbsp;((re&nbsp;l)&nbsp;atom)
&nbsp;&nbsp;(if&nbsp;(equalp&nbsp;atom&nbsp;(slot-value&nbsp;re&nbsp;'letter))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(make-instance&nbsp;'empty)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(make-instance&nbsp;'phi)))

(defmethod&nbsp;part-deriv&nbsp;((re&nbsp;choice)&nbsp;atom)
&nbsp;&nbsp;(with-slots&nbsp;((left&nbsp;left)&nbsp;(right&nbsp;right))&nbsp;re
&nbsp;&nbsp;&nbsp;&nbsp;(make-instance&nbsp;'choice
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:left&nbsp;(part-deriv&nbsp;left&nbsp;atom)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:right&nbsp;(part-deriv&nbsp;right&nbsp;atom))))

(defmethod&nbsp;part-deriv&nbsp;((re&nbsp;seq)&nbsp;atom)
&nbsp;&nbsp;(with-slots&nbsp;((left&nbsp;left)&nbsp;(right&nbsp;right))&nbsp;re
&nbsp;&nbsp;&nbsp;&nbsp;(let&nbsp;((rn&nbsp;(make-instance&nbsp;'seq&nbsp;:left&nbsp;(part-deriv&nbsp;left&nbsp;atom)&nbsp;:right&nbsp;right)))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(if&nbsp;(accepts-empty&nbsp;left)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(make-instance&nbsp;'choice&nbsp;:left&nbsp;rn&nbsp;:right&nbsp;(part-deriv&nbsp;right&nbsp;atom))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rn))))

(defmethod&nbsp;part-deriv&nbsp;((re&nbsp;star)&nbsp;atom)
&nbsp;&nbsp;(make-instance&nbsp;'seq
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:left&nbsp;(part-deriv&nbsp;(slot-value&nbsp;re&nbsp;'expr)&nbsp;atom)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:right&nbsp;re))

(defgeneric&nbsp;match-regexp&nbsp;(re&nbsp;word))

(defmethod&nbsp;match-regexp&nbsp;((re&nbsp;regex)&nbsp;word)
&nbsp;&nbsp;(if&nbsp;(eq&nbsp;0&nbsp;(length&nbsp;word))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(accepts-empty&nbsp;re)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(match-regexp&nbsp;(part-deriv&nbsp;re&nbsp;(first&nbsp;word))&nbsp;(cdr&nbsp;word))))

; testing

(match-regexp&nbsp;(make-instance&nbsp;'choice
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:left&nbsp;(make-instance&nbsp;'seq
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:left&nbsp;(make-instance&nbsp;'l&nbsp;:letter&nbsp;#a)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:right&nbsp;(make-instance&nbsp;'l&nbsp;:letter&nbsp;#c))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:right&nbsp;(make-instance&nbsp;'star&nbsp;:exp&nbsp;(make-instance&nbsp;'l&nbsp;:letter&nbsp;#b)))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(list&nbsp;#b&nbsp;#b))
</pre>
<p>It&#8217;s definately not as concise as the Scala version, partly because of my decision to use generic functions to imitate Scala&#8217;s case-class matching.  If any Lispers happen across this, I&#8217;d really appreciate any comments about how to improve on this.</p>
]]></content:encoded>
			<wfw:commentRss>http://tierseven.net/denizens/marc/blog/2009/08/05/regular-expression-matching-without-a-state-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>show me the matches</title>
		<link>http://tierseven.net/denizens/marc/blog/2009/05/29/show-me-the-matches/</link>
		<comments>http://tierseven.net/denizens/marc/blog/2009/05/29/show-me-the-matches/#comments</comments>
		<pubDate>Fri, 29 May 2009 08:35:20 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://tierseven.net/denizens/marc/blog/?p=105</guid>
		<description><![CDATA[Something that I&#8217;ve never been particularly fond of is the way that Vim does filename completion.  Completing with the first available match and then allowing one to cycle through the remaining matches with &#60;TAB&#62; feels less effecient than presenting only the longest matching portion of the filename, allowing one to further refine the partially-completed [...]]]></description>
			<content:encoded><![CDATA[<p>Something that I&#8217;ve never been particularly fond of is the way that Vim does filename completion.  Completing with the first available match and then allowing one to cycle through the remaining matches with <tt>&lt;TAB&gt;</tt> feels less effecient than presenting only the longest matching portion of the filename, allowing one to further refine the partially-completed string or retrieve all candidates using <tt>&lt;TAB&gt;&lt;TAB&gt;</tt>.  The latter is, of course, the model used by bash and Emacs.</p>
<p><a href="http://www.fuzz.dk/software/vim/filename_completion">As it turns out</a> Vim has options that control this behaviour:</p>
<pre>&nbsp;&nbsp;&nbsp;set wildmode=longest:full
&nbsp;&nbsp;&nbsp;set wildmenu</pre>
<p>This <tt>wildmode</tt> setting instructs Vim to complete only the longest common portion of the filename and, if <tt>wildmenu</tt> is enabled, display the candidates in a status menu.  This <tt>wildmenu</tt> setting, of course, turns this feature on.</p>
]]></content:encoded>
			<wfw:commentRss>http://tierseven.net/denizens/marc/blog/2009/05/29/show-me-the-matches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>emacs &amp; slime for people like me</title>
		<link>http://tierseven.net/denizens/marc/blog/2008/11/04/emacs-slime-for-people-like-me/</link>
		<comments>http://tierseven.net/denizens/marc/blog/2008/11/04/emacs-slime-for-people-like-me/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 15:37:40 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Incidentally]]></category>

		<guid isPermaLink="false">http://tierseven.net/denizens/marc/blog/2008/11/04/emacs-slime-for-people-like-me/</guid>
		<description><![CDATA[Peter Christensen has published his &#34;Ultimate n00b SLIME/Emacs cheat sheet&#34; as a Work In Progress.  It&#8217;s a very handy quick reference.
]]></description>
			<content:encoded><![CDATA[<p>Peter Christensen has published his &quot;<a href="http://www.pchristensen.com/blog/articles/public-beta-open-for-ultimate-n00b-slimeemacs-cheat-sheet/">Ultimate n00b SLIME/Emacs cheat sheet</a>&quot; as a Work In Progress.  It&#8217;s a very handy quick reference.</p>
]]></content:encoded>
			<wfw:commentRss>http://tierseven.net/denizens/marc/blog/2008/11/04/emacs-slime-for-people-like-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>punch clock: an introduction to objective-c</title>
		<link>http://tierseven.net/denizens/marc/blog/2008/05/31/punch-clock-an-introduction-to-objective-c/</link>
		<comments>http://tierseven.net/denizens/marc/blog/2008/05/31/punch-clock-an-introduction-to-objective-c/#comments</comments>
		<pubDate>Sat, 31 May 2008 16:57:11 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://tierseven.net/denizens/marc/blog/2008/05/31/punch-clock-an-introduction-to-objective-c/</guid>
		<description><![CDATA[My first attempt at using Objective-C for something useful has produced Punch Clock, a simple application that one might use to record one&#8217;s activities for personal time management or later entry in a time-tracking system or timesheet.
While it is, as an application, little more than a skeleton of a prototype, it has enough useful functionality [...]]]></description>
			<content:encoded><![CDATA[<p>My first attempt at using Objective-C for something useful has produced <i>Punch Clock</i>, a simple application that one might use to record one&#8217;s activities for personal time management or later entry in a time-tracking system or timesheet.</p>
<p>While it is, as an application, little more than a skeleton of a prototype, it has enough useful functionality to give a flavour of Cocoa development in Objective-C.  It features:</p>
<ul>
<li>post-launch application initialisation through the use of a <code>NSApplication</code> delegate</li>
<li>an editable <code>NSTableView</code></li>
<li>programmatic edits of a table cell</li>
<li><code>NSButton</code>s that are enabled and disabled according to the state of the application</li>
</ul>
<p>Those not completely disinterested can <a href="http://bitbucket.org/sinistral/punchclock/overview/">browse</a> the source.  It is hosted by <a href="http://bitbucket.org">Bitbucket</a> as a <a href="http://selenic.com/mercurial/">Mercurial</a> repository; retrieve it using:</p>
<p>&nbsp;&nbsp;&nbsp;<code>hg clone http://bitbucket.org/sinistral/punchclock</code></p>
]]></content:encoded>
			<wfw:commentRss>http://tierseven.net/denizens/marc/blog/2008/05/31/punch-clock-an-introduction-to-objective-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSLog an NSString</title>
		<link>http://tierseven.net/denizens/marc/blog/2008/03/27/nslog-an-nsstring/</link>
		<comments>http://tierseven.net/denizens/marc/blog/2008/03/27/nslog-an-nsstring/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 03:33:02 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Incidentally]]></category>

		<guid isPermaLink="false">http://tierseven.net/denizens/marc/blog/2008/03/27/nslog-an-nsstring/</guid>
		<description><![CDATA[NSLog(@"hello, %@", @"world");
]]></description>
			<content:encoded><![CDATA[<p><code>NSLog(@"hello, %@", @"world");</code></p>
]]></content:encoded>
			<wfw:commentRss>http://tierseven.net/denizens/marc/blog/2008/03/27/nslog-an-nsstring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>classpath file classloader &#8211; now with properties</title>
		<link>http://tierseven.net/denizens/marc/blog/2008/03/12/classpath-file-classloader-now-with-properties/</link>
		<comments>http://tierseven.net/denizens/marc/blog/2008/03/12/classpath-file-classloader-now-with-properties/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 06:04:07 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://tierseven.net/denizens/marc/blog/2008/03/12/classpath-file-classloader-now-with-properties/</guid>
		<description><![CDATA[The ClasspathFileClassLoader now supports system properties.  Thus, the command line for any Java application need consist of only:
&#160;&#160;&#160;java \\
&#160;&#160;&#160;-Djava.system.class.loader=tierseven.cfcl.ClasspathFileClassLoader \\
&#160;&#160;&#160;-Dtierseven.cfcl.ClasspathFileClassLoader.properties_file=/path/to/cfcl/properties_file \\
&#160;&#160;&#160;-classpath /path/to/cfcl/classes \\
&#160;&#160;&#160;&#60;main_class&#62;

The properties file should contain other properties, including tierseven.cfcl.ClasspathFileClassLoader.file, which will in turn contain the classpath elements.
The source is available from a Mercurial repository:
&#160;&#160;&#160;hg clone http://bitbucket.org/sinistral/cfcl
]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://bitbucket.org/sinistral/cfcl/overview/">ClasspathFileClassLoader</a> now supports system properties.  Thus, the command line for any Java application need consist of only:</p>
<pre>&nbsp;&nbsp;&nbsp;java \\
&nbsp;&nbsp;&nbsp;-Djava.system.class.loader=tierseven.cfcl.ClasspathFileClassLoader \\
&nbsp;&nbsp;&nbsp;-Dtierseven.cfcl.ClasspathFileClassLoader.properties_file=/path/to/cfcl/properties_file \\
&nbsp;&nbsp;&nbsp;-classpath /path/to/cfcl/classes \\
&nbsp;&nbsp;&nbsp;&lt;main_class&gt;
</pre>
<p>The properties file should contain other properties, including <code>tierseven.cfcl.ClasspathFileClassLoader.file</code>, which will in turn contain the classpath elements.</p>
<p>The source is available from a Mercurial repository:</p>
<pre>&nbsp;&nbsp;&nbsp;hg clone http://bitbucket.org/sinistral/cfcl</pre>
]]></content:encoded>
			<wfw:commentRss>http://tierseven.net/denizens/marc/blog/2008/03/12/classpath-file-classloader-now-with-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>syntax error before &#8216;AT_NAME&#8217; token</title>
		<link>http://tierseven.net/denizens/marc/blog/2008/03/04/syntax-error-before-at_name-token/</link>
		<comments>http://tierseven.net/denizens/marc/blog/2008/03/04/syntax-error-before-at_name-token/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 10:14:14 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Incidentally]]></category>

		<guid isPermaLink="false">http://tierseven.net/denizens/marc/blog/2008/03/04/syntax-error-before-at_name-token/</guid>
		<description><![CDATA[I also ran into this rather less-than-obvious error message compiling Objective-C code on MacOS X 10.5:

&#160;&#160;&#160;syntax error before ‘AT_NAME’ token

I eventually resolved it thanks to this blog entry.  The compiler was moaning about a missing @end in a header file.
]]></description>
			<content:encoded><![CDATA[<p>I also ran into this rather less-than-obvious error message compiling <em>Objective-C</em> code on MacOS X 10.5:</p>
<pre>
&nbsp;&nbsp;&nbsp;syntax error before ‘AT_NAME’ token
</pre>
<p>I eventually resolved it thanks to <a href="http://blog.infurious.com/2007/10/22/syntax-error-before-‘at_name’-token/">this blog entry</a>.  The compiler was moaning about a missing <code>@end</code> in a header file.</p>
]]></content:encoded>
			<wfw:commentRss>http://tierseven.net/denizens/marc/blog/2008/03/04/syntax-error-before-at_name-token/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>being objective</title>
		<link>http://tierseven.net/denizens/marc/blog/2008/03/04/12/</link>
		<comments>http://tierseven.net/denizens/marc/blog/2008/03/04/12/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 07:30:50 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://tierseven.net/denizens/marc/blog/2008/03/04/12/</guid>
		<description><![CDATA[I&#8217;ve long been a fan of Apple.  In 1985 my father returned from a US visit with a brand new Macintosh Plus and introduced me to a whole new world of personal computing (You have no idea how big a deal this was to a little South Africa boytjie &#8211; thanks, Dad!).  While [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve long been a fan of Apple.  In 1985 my father returned from a US visit with a brand new Macintosh Plus and introduced me to a whole new world of personal computing (You have no idea how big a deal this was to a little South Africa boytjie &#8211; thanks, Dad!).  While my friends were fighting with <em>phix</em> so that they could play <em>Montezuma&#8217;s Revenge</em>, I had the <em>Dark Castle</em> games.  In later years, however, limited access to (relatively) expensive Apple hardware meant that, by the time I started started programming, all that was available to me was Windows and GNU/Linux on Intel hardware.</p>
<p>It is only recently that I&#8217;ve had the privilege of getting re-acquainted with the beauty that is Apple.</p>
<p>I&#8217;ve been curious about Apple&#8217;s choice of Objective-C and, now that I have the opportunity, I&#8217;ve decided to learn the language for myself.  The bits and bytes that I pick up, I will post here &#8211; mostly as a reminder for myself, but also in the hope that it will help someone else who, like me, is just starting out.  As most of my experience to-date has been as a Java developer, some of the things that took me a little while to figure out will no doubt be blindingly obvious to a C/C++ developer.</p>
<p>So &#8230; my first step was to try to write something very simple that would let me play around with the classes in the standard frameworks.  For me this means being able to do a quick command-line build, without having to fire up Xcode.  What I ended up with is the following <code>main.m</code>:</p>
<pre>
#import "Foundation/Foundation.h"

int main (int argc, char** argv)
{
	NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
	NSMutableArray* records = [NSMutableArray arrayWithCapacity: 3];

	[records addObject: [NSMutableDictionary dictionaryWithCapacity: 2]];
	[records addObject: [NSMutableDictionary dictionaryWithCapacity: 2]];

	[[records objectAtIndex: 0] setValue: @"marc" forKey: @"name"];
	[[records objectAtIndex: 0] setValue: @"male" forKey: @"sex"];
	[[records objectAtIndex: 1] setValue: @"michelle" forKey: @"name"];
	[[records objectAtIndex: 1] setValue: @"female" forKey: @"sex"];

	[records writeToFile: @"entries" atomically: NO];
	[pool release];
}
</pre>
<p>This may be compiled using:</p>
<pre>
&nbsp;&nbsp;&nbsp;gcc -framework Foundation Test.m
</pre>
<p>There were a couple of things that weren&#8217;t immediately obvious to me:</p>
<ul>
<li>
<li>to use the classes in the <code>Foundation</code> framework, one needs to include <code>Foundation/Foundation.h</code>; I was looking for specifc headers files for each of the referenced classes.</li>
<li>the linker must be instructed to link against the framework using the <br />&nbsp;&nbsp;&nbsp;<code>-f <em>&lt;framework&gt;</em></code><br /> option.  If you&#8217;re not linking, a <br />&nbsp;&nbsp;&nbsp;<code>gcc -c main.m</code><br /> is sufficient.
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tierseven.net/denizens/marc/blog/2008/03/04/12/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>learning to lisp</title>
		<link>http://tierseven.net/denizens/marc/blog/2007/09/28/learning-to-lisp/</link>
		<comments>http://tierseven.net/denizens/marc/blog/2007/09/28/learning-to-lisp/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 11:28:23 +0000</pubDate>
		<dc:creator>marc</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://tierseven.net/denizens/marc/blog/2007/09/28/learning-to-lisp/</guid>
		<description><![CDATA[For some time now I&#8217;ve been intrigued by the claims of its proponents that Lisp is the language that exemplifies elegance and expressiveness.  Those are bold claims, and I&#8217;ve finally decided to take the plunge and to see what all the fuss is about.  So, this is my step down the road; only [...]]]></description>
			<content:encoded><![CDATA[<p>For some time now I&#8217;ve been intrigued by the claims of its proponents that Lisp is the language that exemplifies elegance and expressiveness.  Those are bold claims, and I&#8217;ve finally decided to take the plunge and to see what all the fuss is about.  So, this is my step down the road; only time will tell if I&#8217;ll ever truly &quot;get it&quot;.</p>
<p>I find that I learn best by doing, so with the first few chapters of Peter Seibel&#8217;s <a href="http://www.gigamonkeys.com/book/">Practical Common Lisp</a> as an introduction, I wanted to get my hands dirty and started putting together a development environment.  The <b>S</b>uperior <b>L</b>isp <b>I</b>nteraction <b>M</b>ode for <b>E</b>macs (<a href="http://common-lisp.net/project/slime/">SLIME</a>) is by far the most popular (free) Lisp IDE, and it is indeed excellent; I have, however, long been more comfortable with <a href="http://www.vim.org/">Vim</a> and found Larry Clapp&#8217;s <a href="http://www.vim.org/scripts/script.php?script_id=221">VIlisp</a> a functional alternative for interfacing with a Lisp interpreter.  My search for a (free) Lisp implementation eventually ended with <a href="http://ecls.sourceforge.net/">ECL</a>.</p>
<p>My decision to use ECL was based mainly on the fact that it is designed to be used as an embedded library, and can translate Lisp to C to produce a native executable.  I see this as a benefit, because unlike Java (which has a rigid JVM and class format specification), Lisp does not require that <b>fasl</b>s be portable between implementations, so there doesn&#8217;t appear to be a consistent way to distribute Lisp applications in binary form. The binary produced by ECL&#8217;s compilation is linked to the ECL library, which means that users don&#8217;t need to download an additional package (a Lisp interpreter) to run one&#8217;s application. Thanks to Java this is less of an issue now than it once was, but I for one still like to be able to download and use an application without having to hunt down its required framework.<br />
I will, however, be revisiting <a href="http://clisp.cons.org/">CLISP</a> and <a href="http://sbcl.sourceforge.net/">SBCL</a>, which seem to be more user- (read: developer-) friendly Lisp implementations.</p>
<p>But I digress&#8230;  With a development environment now set up, I embarked on my first Lisp project: an implementation of <a href="http://en.wikipedia.org/wiki/Conway's_Game_of_Life">John Conway&#8217;s Game of Life</a>.  The <a href="http://tierseven.net/svn/listing.php?repname=misc&amp;path=%2Fcgl%2F&amp;rev=0&amp;sc=0">source code</a> is available; <a href="http://www.libsdl.org/">SDL</a> is needed for the display.</p>
<p>Initially I, like many others, found the proliferation of parentheses a visual distration that hid the actual code.  It required a good deal of effort to focus on the code and ignore the parentheses.  In a surprisingly short time, however, I began to appreciate the parentheses as visual cues that delimit forms.  They started to function as a kind of scope (in the sniper sense) for widening and narrowing my visual focus, allowing me to always concentrate on a specific context.  I think the brain tends to focus on what it doesn&#8217;t recognise, and the more Lisp code one writes, the less the parentheses will stand out, and the more they will be interpreted as an appropriate visual cue.  From my humble and limited experience, if the parentheses are the only thing stopping you from learning Lisp, try to stick with it &#8230; It may get better.</p>
<p>In addition to the REPL, I found Lisp&#8217;s lambda functions and closures to be an very useful debugging aid.  By wrapping a portion of a function in a lambda function, and assigning it to a global variable, that portion of code is made accessible.  Using <code>funcall</code> one can execute the lambda function to ensure that the fragment it wraps is behaving correctly. Because the fragment uses the bindings that have been captured by the closure, there&#8217;s no need to write test code that injects appropriate test values.  Its not a replacement for proper test cases, but its great for ad-hoc verification of a particular piece of code.</p>
<p>I must say again that I&#8217;ve barely (if at all) scratched the surface of what Lisp has to offer.  However, the little that I&#8217;ve seen has whet my appetite and I&#8217;m eager to learn more.  I&#8217;ve only caught glimpses of the after-images left by the lightning bolts cast by Lisp wizards, but there appears to be a great deal of magic out there &#8230; and I&#8217;m eager to learn more.</p>
]]></content:encoded>
			<wfw:commentRss>http://tierseven.net/denizens/marc/blog/2007/09/28/learning-to-lisp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
