bus scheme



So during RubyConf, Matz asked how many in the audience had written a Lisp implementation. It was pretty impressive—somewhere between five and ten percent of the crowd raised their hands. Unfortunately I was not one of them, to my great shame.

Anyway, I figured it was about time to fix that. I've been coding up a little interpreter on my bus rides to work. Bus Scheme it is called, and it's implemented in Ruby. (I seriously considered doing it in Emacs Lisp, but I've been writing plenty of that these days, and I actually haven't been touching Ruby a lot.) Anyway, it's a lot of fun. I was thrashing about blindly with the parser for a while, but once I discovered the proper way of separating the parsing step from the tokenizing step (thanks Ryan! I did learn this in school once; I promise...) it all fell into place with a bit of recursion.

 > (+ 2 2)
 > (define fives (quote 5 5))
 > fives
 > (concat "foo" "bar")

Right now it's just good for simple arithmetic, basic defines, and a few primitives, but I should be getting to lambda next. I think I'll need to read a little further in The Little Schemer before I'm ready to tackle that, though.

Code is up as a tarball. I haven't figured out where to host the git repository yet. I'm really enjoying the exercise and would recommend it to like-minded hackers. Bonus fact: I haven't actually used a real Scheme yet. Everything I know about it I've gathered from reading The Little Schemer, watching the Structure and Interpretation of Computer Programs videos, and reading lots about Common Lisp and Emacs Lisp—all of which I can't recommend highly enough.

In closing: the video of my RubyConf talk has been posted by ConFreaks. Much thanks to them for taping the conference. There are also a ton of other good videos posted there, though not every talk is up yet. Dig in!

« older | 2007-12-09T15:23:42Z | newer »