Log in

No account? Create an account

Atta, Boy!

Last week a reader expressed a hope that I'll release Apis soon, and I intend to. That reader, though, hoped that Apis was written in Gambit Scheme, and it isn't. It's written in Common Lisp, and uses Clozure Common Lisp's very good Cocoa support.

Do not despair, however, Faithful Reader! I've packaged a Gambit Scheme variant of Apis, called Atta, which you can download here.

Atta is an ultra-simple text editor, the kind that you can build by following along with Apple's tutorial example, "Building a Text Editor in 15 Minutes." Instead of using XCode and pure Objective-C code to implement the text editor, though, Atta uses a mix of Objective-C and Scheme, using Gambit-C's spiffy C interface to make that easy.

The net being what it is, I expect to hear complaints that Atta is trivial. Yes, it is; that's the point. It's a nearly-minimal Cocoa application whose main program and parts of the application logic are written in Scheme.

I also expect to hear complaints that there's hardly any Scheme code--not even as much as the Objective-C code (and there's precious little of that). That's also true, but it's because the application is so trivial. There is just barely enough code to do anything at all, and, what with Scheme code tending to be so compact and all, there's hardly anything to see.

Finally, I'm pretty sure that someone is going to read through the code and complain that the implementations of saving and loading text files are unnecessarily complicated. That's also true, but if they weren't, then there really wouldn't be any scheme code at all. Well, apart from the call to "(begin (cocoa:application-main))".

Atta is intentionally minimal, so that it's easy to read through all the code and see what it's doing. It's not completely minimal, because there needs to be enough code that you can see something being done, and in order to serve that purpose, I implemented parts of the save and load methods in Scheme, though it certainly would have been simpler just to write a line of Objective-C code in each place.

The point of doing it the way I did is that you can trace through the program's logic and see how an NSAttributedString value begins in a Cocoa window, is extracted and passed to Scheme, which then passes it back to Objective-C to convert it to an NSData value, then gets the NSData back and hands it to the original Objective-C context, which writes it to a file. A similar process occurs when opening a file, so you can follow the progress of the data all the way from Cocoa window to disk and back again, passing through Scheme's heap on the way.

In this initial version, the Scheme code doesn't actually do anything with the data, except pass it around. It would probably be useful to think of some transformation to do on it as it whizzes by, in order to better illustrate how Gambit can convert C data to Scheme data and vice versa. I don't want to wait around for inspiration to strike on that point, though, so I've gone ahead and packed up Atta 1.0 and made it available.

Apis should be along as well in pretty short order. It's not any more complicated or difficult to package up than is Atta.

Oh, and somebody's sure to wonder what's up with the names "Atta" and "Apis". They're genus names of insects; specifically, "Atta" is the leafcutter ant, and "Apis" is the honeybee. When I first wrote Apis it was part of an experiment in writing a minimal Cocoa application that could serve as the front-end of a system of cooperating processes. Lots of cooperating processes; a swarm that makes something appealing or useful; honeybees; you get the idea. When I decided to port the basic application framework over to Gambit, I debated using the same name, but I thought, "I still want to release the Common Lisp version, and it would be nice if were easy to distinguish them. It would also be nice if it could have a similarly brief and easy-to-remember name, and if it stuck to the eusocial organism theme established by Apis." There are several eusocial organisms to choose from. "Naked Mole Rat" has its own kind of aesthetic, but just didn't seem quite right. After some consideration, I chose "Atta', the leafcutter ants, because they're eusocial, and I admire their invention of agriculture.

So that's it; the clamoring throng of one or two people who want a simple example of how to build a Cocoa app in Gambit can grab Atta 1.0, and Apis will be along shortly. Bear in mind that for Atta to be of any use, you'll need to have a recent version of Apple's Developer Tools , and also a recent version of Gambit-C.

Have fun!



faithful reader

thanks a lot for taking the time to do this, mike !
Very much appreciated :)
I had to tweak the Makefile a little to remove the -arch bits and add the /usr/local/Gambit-C includes/libs but after that it built great on Snow Leopard with the latest Xcode and Gambit stuff.

Neat stuff!

Does the inline-ish C confuse Emacs at all?
Yeah, the inline C definitely confuses Emacs. Inside those blocks It's reduced to a dumb text editor.

Interesting about the Makefile tweaks. I wonder why? I'm building on Snow Leopard, too. Maybe we have different optional installs?

Apis is getting close. Its Makefile will also require tweaks, in this case because you'll need to tell it where the CCL you want to use can be found.
I don't think I installed 32-bit support when I installed Xcode.

February 2010

Powered by LiveJournal.com