Sunday, October 14, 2007

How I started off with Haskell and wound up with Lisp

A while ago, I started dabbling in the functional programming space. As with many of my other experiments, I started learning Haskell. I mentioned this to a couple of friends and they asked me if it had to do anything with Pascal. I assured them that they had no resemblance whatsoever. I got off with an excellent tutorial on Haskell. But somehow the static typing part had a nagging feeling in the back of my head. I code with C# a lot in my day job. I do not have anything against statically typed languages, but I strongly believe that you can be far more productive with a dynamically typed language.

I then came across this tutorial, which teaches you to write a Scheme interpreter in Haskell in 48 hours. Really Cool. I fell in love with Lisp immediately. I googled for Lisp and I discovered that there are many dialects of Lisp. The most popular ones are Common Lisp and Scheme. I decided to go with Common Lisp for some unknown reason. I guess because it had Lisp in its name :-). I then had to find the right implementation for my platform. Being a GNU fan, I picked the GNU CLISP. As it turns out, it is a horrible implementation which does not support threading and is painfully slow. But it was fine for the small programs that I use for learning. I have Ubuntu Feisty on my "home" laptop but I spend most of my time on the office laptop which as you all might have guessed, runs "Windows". There are many good commercial implementations for Windows but I was looking only for open source software. GNU CLISP seems to be the only fully functional Common Lisp implementation. I've worked with SBCL and found that okay too. I did not run into any major issues but their website has an yellow status for SBCL on Windows and a big bold notice saying that it is an experimental implementation. But for learning purposes, I guess it is just fine.

I followed a really cool Lisp tutorial, which is actually a book by a guy called Peter Seibel named Practical Common Lisp. It is a free online resource.

One of my biggest barriers to entry was my text editor. I was a 'vi' guy. As I browsed for help on Lisp, I kept finding these cool emacs extensions for lisp programming. I then took the dive and started using Emacs. It was very painful in the beginning. My fingers automatically pressed the and the ':' keys whenever I wanted to do something. But it took about a week of exercise to train my mind to work with Emacs. Writing extensions for vim is a big deal and normal users would not do it. But extending emacs is a piece of cake. It can be done one step at a time and is very well documented. BTW, I am writing this blog on Emacs. One thing VI does not have is the 'longlines-mode'. If there is one, please let me know. Emacs is just not a text editor but the text editor for me. One more cool thing about using Emacs to code common-lisp is that, you can turn it into a Lisp IDE. Slime(a horrible name) is a mode in emacs that turns your modest text editor into a full blown IDE, including code assist and interactive debugging, even on remote machines.

So this is your startup kit for learning Lisp.
Happy coding!

Friday, October 05, 2007