Tuesday, July 15, 2003

Learning Scheme

Yesterday I started to learn the Scheme programming language, and this morning I got the idea to journal the learning process in a weblog.

Scheme is a variation or dialect of the Lisp programming language. I've been interested in Lisp for about 17 years, ever since I did some exploratory research into artificial intelligence. Unfortunately, I couldn't run Lisp on any of the computers to which I had access at that time so I didn't learn it then. My work took me in other directions and other programming languages, so I never had a clear professional reason to learn it.

As I got into weblogs early last year, I also got exposed to people like Dave Winer who advocated the use of scripting languages to increase productivity. I dabbled in Ruby, started to learn Python, and brushed up on my ancient knowledge of Perl. However much I recognized the merits of these languages, though, I never fell in love with them.

There were a couple of other weblogs that I started reading, Lambda the Utlimate, and Lemonodor. Lambda is about programming languages, with a heavy dose of functional programming. Lemonodor is all about Lisp. These blogs reawakened my interest in Lisp, so eventually I decided to learn it.

Lisp is a language with a lot of variants known as dialects. It has evolved a lot over the years, with different dialects taking radically different approaches. What the dialects do have in common is the heavy use of the list data structure, with programs as well as data expressed as lists. This idea of a program being data has always fascinated me.

Today, there are two heavily used Lisp dialects: Common Lisp, and Scheme. Common Lisp is big and powerful, and Scheme is small and elegant. This is not to say the Common Lisp is without elegance, or Scheme is without power, but in the world of compromises that make up programming language design, Common Lisp seems to emphasize power, where Scheme emphasizes elegance.

Although the design goal of small and elegant attracted me to Scheme, whenever I looked at code comparisons between the two, Common Lisp code was usually the more compact, so I was leaning towards Common Lisp. I downloaded OpenMCL for my Macintosh, as well as some tutorial material, ready to tackle Common Lisp. Unfortunately, OpenMCL does not have an IDE, and BBEdit doesn't really help out for Lisp. Vi has a nice parenthesis matching function, but the real editor for Lisp is Emacs. I have great respect for Emacs, but it doesn't really fit my Macintosh environment. Also, my hope is to use Lisp as a scripting language, not only for personal use, but on my PC at work, too. A nice Common Lisp IDE was going to cost me about $500 for the PC and over $900 for the Macintosh. If I ever need Common Lisp for a serious project, it may be worth it, but I can't justify that kind of money right now.

Then I remembered DrScheme, which I learned about on one of the weblogs. I downloaded it and began going through a tutorial it has for teaching Scheme to experienced programmers called Teach Yourself Scheme in Fixnum Days. I began work on it during my bus ride to and from work yesterday. DrScheme is a nice environment and Fixnum is a good tutorial. Yesterday evening I wrote my first loop using tail recursion, and I fell in love.

I will admit that after one day, I cannot be sure if this is true love, but already I see a beauty in Scheme that attracts me. I've written a long enough introduction, so I will save the specifics for later, and we will see if this initial crush develops into a steady relationship.

No comments: