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!

9 comments:

Anonymous said...

When your done with Sielbel book take a look at Norvig's "Paradigms of Artifical Intelligence Programming" (a lisp book). You might be able to find or download Paul Graham's excellent "On Lisp" too.

- I went the other way, from Lisp to Haskell :) but each to his or her own path.

Unknown said...

Thanks for the tip. Those are definitely on my reading list.

Bill Mill said...

"gj" moves down one "visual line" instead of actual line, for short stuff. For longlines-mode, see this tip; in the comments somebody wraps it into a function.

Also, you find writing functions in vim hard work?

Unknown said...

Thanks a lot for the vim tip. But vim script is a little odd when compared to elisp. :-) I dont wish to start a flame war here. It is just my humble opinion.

Anonymous said...

>it is a horrible implementation

I don't think horrible is the right word... CLISP is more like a scripting variant of LISP. For example it has way better support for calling external programs that SBCL.

Unknown said...

Hmm... thats strange. I never thought of it. I understand that common lisp evolved from Lisp Machines where Lisp was itself the operating system. But I believe that Common Lisp should add Process Management as a part of its hyperspec. You can learn a thing or two from Python's subprocess module.

Anonymous said...

Vagmi -- out of interest, what did you find more productive about Lisp than Haskell?

Unknown said...

Strangely, I find Lisp more productive. But there is a BIG catch with Lisp. But libraries are a problem. I guess it is particularly to do with Common Lisp. May be Scheme is better.

As far is absolute productivity is concerned for really important stuff, choose the language you are most comfortable with. My brain is very comfortable with Python AND Ruby. I find myself the most productive using Python.

If it is a pure choice between Haskell and Lisp, I would choose Lisp any day.

Anonymous said...

If you like moving around the vim way and want the nice lisp features found in emacs you can use the vimpulse and viper modes for emacs. It's not perfect but it's actually pretty nice.

check it out at
http://www.emacswiki.org/emacs/vimpulse.el