Wednesday, January 24, 2007

Starting up with SBCL

I've recently started working with SBCL on an intel Mac OS X machine. SBCL has come a long way since the last time I had attempted using it, two years ago. It has a different set of quirks from Allegro CL, which I've been using for many years now. My baseline for considering SBCL usable was whether I could get FReT to work. Happily I have succeeded. Version 0.3.1 doesn't work, version 0.3.2 (or the current svn head) will.

The most difficult task in porting FReT was odd bugs that came up in CLOS. FReT does a lot of CLOS mangling. And while I find CLOS to be one of the most powerful and capable OO systems I've used, it is also one of the most mysterious. I was defining and redefining classes, and using their prototypes for selecting generic function methods to execute. In addition, I had added default initialization forms in class definitions to signal errors if certain slots were not supplied, like so:
(defclass test-object ()
((start-time :initform (get-universal-time) :reader test-start-time)
(state :initform :init :accessor test-state)
(runner :initarg :runner :initform (error-required 'runner 'test-object) :reader test-runner)))

SBCL, it turns out, applies slot initialization on prototype instances when a class is redefined, but not when the class is initially defined. This is apparently allowed by the ANSI standard. I'm not that great at following the minutiae of standards, so I am not going to try and explain why this is possible. The solution turned out to be including an error handler in an :around method for update-instance-for-redefined-class.

I'm presently satisfied that SBCL is usable, though not necessarily immediately comprehensible. Suitable for my hacking needs.