Author Archive for marc Page 4 of 4



learning to lisp

For some time now I’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’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’ll ever truly "get it".

I find that I learn best by doing, so with the first few chapters of Peter Seibel’s Practical Common Lisp as an introduction, I wanted to get my hands dirty and started putting together a development environment. The Superior Lisp Interaction Mode for Emacs (SLIME) is by far the most popular (free) Lisp IDE, and it is indeed excellent; I have, however, long been more comfortable with Vim and found Larry Clapp’s VIlisp a functional alternative for interfacing with a Lisp interpreter. My search for a (free) Lisp implementation eventually ended with ECL.

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 fasls be portable between implementations, so there doesn’t appear to be a consistent way to distribute Lisp applications in binary form. The binary produced by ECL’s compilation is linked to the ECL library, which means that users don’t need to download an additional package (a Lisp interpreter) to run one’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.
I will, however, be revisiting CLISP and SBCL, which seem to be more user- (read: developer-) friendly Lisp implementations.

But I digress… With a development environment now set up, I embarked on my first Lisp project: an implementation of John Conway’s Game of Life. The source code is available; SDL is needed for the display.

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’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 … It may get better.

In addition to the REPL, I found Lisp’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 funcall 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’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.

I must say again that I’ve barely (if at all) scratched the surface of what Lisp has to offer. However, the little that I’ve seen has whet my appetite and I’m eager to learn more. I’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 … and I’m eager to learn more.

changing LaTeX’s default document font

The following in a document preamble may be used to change LaTeX’s document font to the sans-serif default: renewcommand{familydefault}{sfdefault}

multi-user svn+ssh access

I’ve discovered that it is possible to configure svnserve such that multiple users can commit under their own (svn) names while sharing a single system account (via svn+ssh). It might be handy for those who have subversion respository in a shared hosting environment.

The details are available here.

a cygwin package cleaner

Cygwin is invaluable to any Windows developer used to (or even just familiar with) the tools that are available in a GNU/Linux development environment.

Probably the only complaint that I have is that the setup tool doesn’t take care of cleaning up old packages. While I don’t have all of the packages installed, I have enough of them that I don’t want to have to prune the packages by hand. Enter cygpkgclean; its a little PERL script that deletes all packages except the current and previous versions (of both binary and source packages). It doesn’t yet cater for packages that are no longer in the setup.ini or that have moved to a new directory.

I had hoped to implement this as nothing more than a bash script (so that it would run on the barest of cygwin installations), but that proved to be a little beyond my meager script-fu (for now!).

classpath file classloader (++revision)

The latest revision of the CFCL fixes a fatal bug and is greatly simplified over the previous version.

The first version of was a lot more complex that it needed to be. In a misguided attempt to avoid a recursive loader invocation, I had ClasspathFileClassLoader extend ClassLoader, and used an inner class that extended URLClassLoader. This meant that CFCL should have obeyed the standard classloader rules of engagement, which it unfortunately didn’t.

Requests to the inner URLClassLoader were always made using findClass(), which (for all but the simplest of applications) will result in a ‘duplicate definition’ error when a load is requested for a class that has already been defined. What CFCL should have done is first issue a findLoadedClass() request, and only if that returned null attempt to load the class using findClass().

As it turns out, its not a problem have CFCL extend URLClassLoader; this greatly simplifies the code as the inner class is no longer necessary, and CFCL can simply rely on URLClassLoader to correctly implement the required class loader semantics. This also makes the class much easier to maintain because I no longer have to worry about managing resource loading, signers, etc; something I would have had to do had CFCL continued as a facade.

classpath file classloader

As a self-confessed command-line junkie, the amount of work that is required to start a Java application has always bothered me.  The command-line for any application that requires more than one or two .jar files or class file directories to be specified quickly becomes a nightmare to type, and one very often has to resort to a shell script.  While I have no problem with shell scripts per se, it seems only slightly less inconvenient to write a shell script for every application (with its own unique classpath) that I want to run, than it is to type the command-line for that application (especially when writing throwaway test classes).

As a first step to reducing the overhead involved in setting up a classpath, I have written a class loader that is able to read the classpath elements from a (set of) files.

Each line in the file must represent either a directory or .jar file that would normally be added using the -classpath switch.  One can also use a #include directive to specify a directory that must be searched (non-recursively) for .jar files that must be added to the classpath. If the #import directive to include a regular file, that file will be read as a classpath file. For example, a classpath file may look something like:

#include /usr/local/lib/javalibdir
#include /home/user/directory/.classpathfile
/some/relative/directory/lib.jar

The initial classpath file is specified using the system property tierseven.cfcl.ClasspathFileClassLoader.file and the system property tierseven.cfcl.ClasspathFileClassLoader.verbose may be used to activate debug output. The class loader itself should be installed as the system class loader by using the system property java.system.class.loader. For example:

java -Djava.system.class.loader=tierseven.cfcl.ClasspathFileClassLoader -Dtierseven.cfcl.ClasspathFileClassLoader.file=.classpath -classpath . <main_class> <cmd_line_parameters>

This is still really much longer than i’d like it to be (mostly because of the properties) but at least this can be used in a generic shell script that can be used to start any application (if the classpath file location is parameterised).The source is available under the BSD license and is a work in progress.