Tuesday, August 12, 2008

The One True Cross

I've been playing with Scheme, and have (almost reluctantly) concluded that Gambit Scheme might be the One True Cross.

If you've not played with Scheme, it's a reasonably minimalist Lisp dialect characterized by a single namespace (functions and variables share single namespace) and lexical scope (variables are bound as they are defined, rather than as they are called). Scheme is Lisp, with all the complexity and magic that implies.

I started playing with Scheme a little when reading The Little Schemer this last spring; but I wasn't in love with it enough to actually try using it. But in the last three weeks, I have suddenly found myself playing more and more... and actually getting useful code written!

I've been using Gambit, which is a Scheme renowned for its abilities in massive concurrency and parallelization. In English, Gambit is very good at allowing a programmer to spawn a number of autonomous computations that occur more or less simultaneously. So instead of doing A, then B, then C; Gambit lets you do A & B & C, all at once.

But Gambit's real strengths for me lay in three lesser-touted features:

  1. Gambit has simple and powerful hooks into the host operating system. This is a major deal after trying for ages to get something close to usable out of Common Lisp for day-to-day hack scripts. See, in the end my life is rather dull: I don't need to encrypt huge amounts of data or write a new programming language nearly as frequently as I need to back up files or directories on my laptop. Common Lisp makes it easy to do the former, not so easy to do the latter. But Gambit steps in with some simple functions like file-exists? or directory-files to test for file existence or find directory contents, respectively. It was very simple to write Scheme equivalents to the Perl commands I use the most (-x, -d, etc.) and suddenly Gambit was teaming with admin scripting potential!

  2. Gambit has a script mode. So instead of starting up a REPL, loading some files, and throwing off complex-looking commands; Gambit lets me start a file with something like #!/usr/bin/gsi-script and get stuff done.

  3. Gambit can compile Scheme code to C, thence to native binaries. This is a major win, because it means I can write something in Scheme, compile it and distribute it as native code, and the end user has no idea what language it was written in. Best of all, a script can be run via gsi-script until it seems stable, then it can be compiled to C and thence to binary without further ado. They can be tested as scripts, and compiled when they pass testing.



One more thing, Gambit's fast: recursive directory tree walks are like lightning. I've been using a simple backup program I wrote in Gambit, and it zooms through copying my data.

But I'm starting to figure out what others have hinted at: Lisp (and Scheme) is more of a phenomenon than a programming language. You don't just learn Scheme; you explore it. And as you explore it, you start to slowly see the depths of potential that your computer doesn't know it has. Scheme becomes a road to enlightenment, not a language to make computers do stuff.

2 comments:

Stace' said...

I totally agree!!!!

Ames said...

My favourite part is the compiler includes several powerful program transformations such as user procedure inlining, partial-evaluation, and lambda-lifting.