programming (and other) musings
20 May 2007

playing with eli's toys

Some weeks ago, as a way to give a serious try to the PLT environment, i wrote my first (and only so far) PLT package, MzFAM, a File Alteration Monitor for MzScheme. MzFAM consists of a set of PLT-scheme modules providing utilities to monitor and react to filesystem changes. It exports a high-level interface consisting of monitoring tasks that run as independent threads and invoke callback procedures each time a file alteration is detected. These high-level tasks are implemented using either Linux's FAM/Gamin monitors or, in systems where it is not available, a pure Scheme fall-back implementation. (A native implementation for BSD systems, based on the kevent/kqueue system calls (see also this nice article to learn more), is on the works.)

As you'll see in the link above, i took the time to (try to) write a decent user manual, using tex2page (which is included in the PLT distribution, but can be used as a standalone program), a nice tool to write HTML manuals using TeX markup and, if you're so inclined, embedded Scheme directives.

MzFAM's implementation served me as an introduction to a couple of wonderful Scheme libraries, both of them authored by Eli Barzilay. In the first place, i needed a foreign function interface to access FAM's C library. Eli's FFI is just a piece of beauty: aided by the magic of dlopen and friends, one can access C libraries without writing a single line of C code. See, for instance, this wrapper of the kevent/kqueue system calls, which will hopefully work as a non-trivial example while you read the FFI manual. Will Farr has also put the FFI to pretty good use recently.


MzFAM has to choose at run time among several underlying implementations of the monitoring, and i've used generic functions to fulfil this need. No rocket science here: run-of-the-mill polymorphism is enough, but i took the chance to play with the second of Eli's jewels, namely, his implementation of CLOS for Scheme, Swindle. Now, Scheme object systems are a dime a dozen, and many of them claim some degree of resemblance to CLOS, but Swindle is, by a long stretch, the closest to the real thing i've used–why, there're even some syntactical spots where it is actually nicer than CLOS itself, and is the only (besides Dorai Sitarm's ScmObj) Scheme object system i know of that provides before/after/around advising. Swindle also comes with a fairly complete MOP implementation, and i'm looking forward to using it after reading Andreas Paepcke's book on CLOS (which, incidentally, i bought after reading its freely available chapter 3, User-Level Language Crafting: Introducing the CLOS Metaobject Protocol (PS)). All that said, please don't take MzFAM as a good example of putting CLOS to work: i'm just a beginner.

Finally, let me mention another nice PLT feature i've used (although this one is not, as far as i know, an Eli's hack): the PLaneT Package Repository. Extremely convenient, and a breeze to set up, both from the user's and the developer's perspective, and yet another reason for giving PLT a serious try.

Happy monitoring!

Tags: programming auld
Creative Commons License by jao is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.