The End of the Line

As usual, you could keep working with this code to enhance it in various ways. One interesting avenue to pursue is to use the underlying output generation framework to emit other kinds of output. In the version of FOO you can download from the book’s Web site, you’ll find some code that implements CSS output that can be integrated into HTML output in both the interpreter and compiler. That’s an interesting case because CSS’s syntax can’t be mapped to s-expressions in such a trivial way as HTML’s can. However, if you look at that code, you’ll see it’s still possible to define an s-expression syntax for representing the various constructs available in CSS.

A more ambitious undertaking would be to add support for generating embedded JavaScript. Done right, adding JavaScript support to FOO could yield two big wins. One is that after you define an s-expression syntax that you can map to JavaScript syntax, then you can start writing macros, in Common Lisp, to add new constructs to the language you use to write client-side code, which will then be compiled to JavaScript. The other is that, as part of the FOO s-expression JavaScript to regular JavaScript translation, you could deal with the subtle but annoying differences between JavaScript implementations in different browsers. That is, the JavaScript code that FOO generates could either contain the appropriate conditional code to do one thing in one browser and another in a different browser or could generate different code depending on which browser you wanted to support. Then if you use FOO in dynamically generated pages, it could use information about the User-Agent making the request to generate the right flavor of JavaScript for that browser.

But if that interests you, you’ll have to implement it yourself since this is the end of the last practical chapter of this book. In the next chapter I’ll wrap things up, discussing briefly some topics that I haven’t touched on elsewhere in the book such as how to find libraries, how to optimize Common Lisp code, and how to deliver Lisp applications.


1The analogy between FOO’s special operators, and macros, which I’ll discuss in the next section, and Lisp’s own is fairly sound. In fact, understanding how FOO’s special operators and macros work may give you some insight into why Common Lisp is put together the way it is.

2The :noescape and :attribute special operators must be defined as special operators because FOO determines what escapes to use at compile time, not at runtime. This allows FOO to escape literal values at compile time, which is much more efficient than having to scan all output at runtime.

3Note that &attributes is just another symbol; there’s nothing intrinsically special about names that start with &.

4The one element of the underlying language-processing infrastructure that’s not currently exposed through special operators is the indentation. If you wanted to make FOO more flexible, albeit at the cost of making its API that much more complex, you could add special operators for manipulating the underlying indenting printer. But it seems like the cost of having to explain the extra special operators would outweigh the rather small gain in expressiveness.