Spork Code

Code. Randomness. Sporks.

Run Your Own Virtual Lisp Machine

with 2 comments

I came across a really interesting project the other day (while browsing Hacker News) by a guy named Brad Parker. Basically, he is writing a specialized virtual machine for CADR (which was an OS for the now defunct Lisp Machines of the 80s). The project has plenty of bugs left for squashing, but in its current state it works quite well. Here’s how to set up your own virtual Lisp Machine.

As always, we have some tarballs to grab:

# this is the VM itself
wget http://www.unlambda.com/download/cadr/usim.tar.gz

# this is a disk image for the VM. If you prefer, you can
# build one of these yourself (there is some documentation on the website)
wget http://www.unlambda.com/download/cadr/disks/disk-with-state.tgz

Now let’s untar them:

tar -xvvf usim.tar.gz
tar -xvvf disk-with-state.tgz

We need to copy the resulting disk.img and usim.state into the /usim directory, because otherwise the ./usim executable we will be using complains about missing .bin files. The usim.state file contains the state of the disk.img; without it you wouldn’t be able to boot the image.

cp disk.img usim/disk.img
cp usim.state usim/usim.state

Ok, now all that is left is to boot up your virtual Lisp Machine:

cp usim/

# this command boots your Lisp Machine in a X window.
./usim -w

The VM should prompt you for the current time, which you can enter in plain English and it will parse for you. Unfortunately, It doesn’t seem as though the original creators of the OS thought that anyone would be using it in 2009, as when you enter 2009 as the year, it thinks you are living some time in the 19000th century. Yes, with 3 zeros. Be forwarned that there are some graphical glitches with the VM, but nothing that a ^C or two won’t fix.

If you are feeling particularly rebellious and you don’t want to use the default disk.img and supplied disk state, you can always make your own. Generating a new disk state is a simple ./usim -S away. Making a new disk is slightly more complicated, but still not particularly bad. you can find documentation on how to do so here.

If you are interested in reading up on CADR, here is the original paper on it (be forewarned, it is quite technical).

What Now?
So now you have your beautiful Lisp Machine up and running, its time to learn some LISP. The manual for programming this Lisp Machine can be found here.


Written by John Gunderman

July 12, 2009 at 3:02 pm

Posted in Uncategorized

Tagged with ,

Installing the Haskell Platform in Ubuntu

with 25 comments

After my previous article about installing Haskell’s Cabal package in Ubuntu, I decided to do a bit more research on using Haskell in Ubuntu. It turns out that the debian packages in the Ubuntu repositories for Haskell and GHC are hopelessly out of date, excluding not only the added functionality of new releases, but also the Haskell Platform, which is effectively an extended set of standard libraries surrounding Haskell. Funnily enough, the Haskell platform actually includes Cabal, which effectively makes my previous post useless. In its stead, I present to you a guide on installing GHC and the Haskell platform on your Ubuntu system (though these steps should work equally well on any Linux system with apt-get as a package manager).

First things first, lets get the dependencies out of the way.

sudo apt-get install libedit2 libedit-dev freeglut3-dev libglu1-mesa-dev

Now let’s remove any haskell packages we may have installed, as these will cause conflicts.

sudo apt-get autoremove ghc6

Note that if you installed cabal as per my previous post, you can remove the executable from your $PATH by executing the following:

sudo rm /usr/local/sbin/cabal 

This will not delete the executable, which is stored in $HOME/.cabal/bin/. This just removes the sym-link that was in your $PATH.

Next, lets grab the source for GHC 6.10.3 (which is required to build the Haskell Platform)

wget http://haskell.org/ghc/dist/6.10.3/ghc-6.10.3-i386-unknown-linux-n.tar.bz2

and untar it.

tar -xvvf http://haskell.org/ghc/dist/6.10.3/ghc-6.10.3-i386-unknown-linux-n.tar.bz2

next, lets configure it and build it:

cd ghc-6.10.3/
sudo make install

After this, installing the Haskell Platform is just more of the same:

#grab the tarball
wget http://hackage.haskell.org/platform/2009.2.0.1/haskell-platform-2009.2.0.1.tar.gz

# untar it
tar -xvvf http://hackage.haskell.org/platform/2009.2.0.1/haskell-platform-2009.2.0.1.tar.gz

# ... and install it.
cd haskell-platform-2009.2.0.1/
sudo make install

Along the way, the install scripts for the Haskell Platform will give you prompts for the next step to take.

Enjoy your Haskell Platform, and happy developing!

Written by John Gunderman

July 11, 2009 at 6:16 pm

Posted in Uncategorized

Tagged with , ,

Weak References in Java: Working around the Garbage Collector

with 2 comments

Weak References are a slightly obscure, but extremely useful, feature of Java. They effectively give you a reference to an object that is ignored by the garbage collector! What does this mean? This means that if an object only has weak references pointing at it, it is eligible for GC. Weak references come in three types: WeakReference, SoftReference, and PhantomReference. Now, I could give you a detailed analysis of all of these types, but instead I will point you to the very well written blog post by Ethan Nicholas.

Read away!

Written by John Gunderman

July 10, 2009 at 7:02 pm

Posted in Uncategorized

Haskell Cabal in Ubuntu

with 8 comments

EDIT: You may prefer to install the entire haskell platform in one go, which includes cabal. Detailed instructions can be found here.

Recently I’ve begun to learn Haskell, the lazy functional language. Haskell is backed by a large library of packages, called Hackage. On Hackage, libraries and programs in a wide variety of genres are available for download. In order to simplify the download and install process for these packages a tool was born to allow command line grab/install maneuver. Think apt-get for Haskell.

The tool in question is called cabal, and it’s quite useful during Haskell development. Unfortunately, I’ve run into some issues while using it, mainly to do with resolving dependencies. I’ll get to that later.

Installing Cabal
Installing cabal was not as straight-forward as I had hoped. I first went to the offical cabal download page, to see what my options were. The only option on that page was to download a tarball and install it by hand. Of course, having been pampered by the power of apt-get, I figured there had to be a better way. Unfortunately, it seems as there is not. No cabal package exists in the Ubuntu repositories. I downloaded the tarball and prepared to install. The install from the tarball was painless as manual installs go, but unfortunately I had to resolve multiple dependencies to get the build to succeed. Here were the steps I took:

#get our dependant libraries (this assumes we already have ghc6 installed)
sudo apt-get install libghc6-network-dev libghc6-parsec-dev libghc6-mtl-dev libghc6-zlib-dev

#grab the source
wget http://haskell.org/cabal/release/cabal-install-0.6.2/cabal-install-0.6.2.tar.gz

#untar it
tar -xvvf cabal-install-0.6.2.tar.gz

#install it
sh cabal-install-0.6.2/bootstrap.sh

#link the executable into our path
sudo ln -s $HOME/.cabal/bin/cabal /usr/local/bin/cabal

Using Cabal

Cabal is not limited to simply downloading libraries. It can also allow you to easily create libraries of your own and upload them to Hackage, and also build projects (similar to make).

cabal --help will bring up your main options, which is always a good starting place. Let’s look at installing a package using cabal.

cabal install [package-name] installs the given package name. This should be very familiar to anyone who has used a package manager such as apt-get.

cabal list [string] is like apt-cache; it searches Hackage for packages pertaining to the string you entered.

Explore! Have fun! there’s plenty more features of cabal that I won’t be covering now, yet are plenty awesome.

I’ve had some strange dependency issues; for example, installing bloxorz –
cabal install bloxorz
gives me an error while trying to build a dependency that in turn depends on a C library which is not auto-resolved. Fun. Fortunately, such errors seem to be few and far between.

Written by John Gunderman

July 5, 2009 at 9:18 pm

Posted in Uncategorized

Tagged with , ,

On Writing Blog Posts

leave a comment »

When I first started this blog, I felt enthused about writing a wide range of interesting articles. Every day, I would learn something new, and then I would blog about it (or so I thought). It turns out that I under-estimated a fear I have apparently harboured: sounding like a stupid ass. Seriously – I was afraid of writing about the things I was learning because I felt that I didn’t know enough about whatever it was to actually sound intelligent. I’ve been there before, reading something I wrote and realising that I sounded clueless. Today I mean to change that. With all my future blog posts, I suppose I will have plenty of opportunities to sound like an ass, but I’m just giving you all a disclaimer: read at your own risk. Hopefully I can learn and write enough to get some good posts out there. We’ll have to see.

Written by John Gunderman

July 5, 2009 at 5:13 pm

Posted in Uncategorized

HTTP Posts in Apache’s new HttpClient 4.0 (with Lighttpd)

leave a comment »

Apache is developing a new HTTP library which is not based on the current Commons libraries. The documentation on the new libraries can be found here. I came across the new library while developing for Google’s Android platform, which uses HttpClient 4.0 for its HTTP protocol handling. The new libraries work well, but I spent a considerable amount of time trying to figure out why it was that I couldn’t get my server to accept the information I had POSTed to it. I finally discovered that the issue was with Lighttpd. Lighttpd was the web server used for the service I was POSTing to. It turns out that Lighttpd has had a long-standing issue with the Expect 100-Continue header. Fortunately, this issue has been resolved in Lighttpd 1.5, but for earlier versions it had never been patched. I had to turn, instead to a rather obscure function which disabled that header. Here is the code:

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);

HttpProtocolParams.setUseExpectContinue(params, false);
try {
   StringEntity se = new StringEntity( /* post params went here */ );
} catch (UnsupportedEncodingException e1) {
try {
   HttpResponse resp =  client.execute(post);
} catch (ClientProtocolException e) {
} catch (IOException e) {

Written by John Gunderman

June 30, 2009 at 9:50 pm

Posted in Uncategorized

Tagged with , , ,

Write Yourself a Scheme in 48 Hours

leave a comment »

I’ve always had issues with finishing projects I start, but I think I’ve found something that I will be able to finish. It is a handy little Wikibook called Write Yourself a Scheme in 48 Hours. Now I tend to be skeptical of any book that purports to teach a topic so many days, or so many hours. However, WYaS is not quite of the same variety as those boastful primers. WYaS is a book with a dual purpose. As the title states, it teaches the reader how to write the majority of a real Scheme interpreter. The language it is presented in is Haskell. According to the author of the book. the reader should end up learning both Haskell and Scheme. Personally, I am inclined to believe him, because I’ve read through the first chapter or so and have been suitably impressed. Hopefully I’ll be able to keep it going and actually finish a programming book for once. If you are even remotely interested in either of these languages or if you simply want a good book to read, I would definitely suggest reading through WYaS and seeing how you like it. I’ll keep you all updated if I come across anything interesting while reading it.

Written by John Gunderman

June 30, 2009 at 4:46 am

Posted in Uncategorized

Tagged with , ,