Technology: October 2003 Archives

On Lisp...

| | Comments (0)

I’ve been playing a little with learning Lisp (not that I’ve much free time, but hey, what the hell). This example, taken from Dave Lamkins’ Successful Lisp, more than any other that I’ve seen so far, expresses the power of the language.

(defun open-bracket (stream char)
    `',(read-delimited-list #] stream t))
(set-macro-character #[#'open-bracket)
(set-macro-character #] (get-macro-character #)))

Here’s what’s happening: we’re redefining the syntax of the language dynamically! Normally, if I type [1 2 3] into a Lisp interpreter it will raise an error, something along the lines of variable [1 has no value, but after running that little code snippet I can now type [1 2 3] and it will create a three element list populated with the numbers 1, 2, and 3. Here’s the equivalent in a Java like syntax.

class OpenBracket implements JavaLanguageParser {
    static List list;
    public void nextToken(RuntimeEnv env, StreamTokenizer stok) {
        if (list == null)
            list = new ArrayList();
        int tok = stok.nextToken();
        if (tok == TT_WORD)
            list.add(stok.add(stok.sval));
        else if (tok == TT_NUMBER)
            list.add(new Double(stok.nval));
    }
}

class CloseBracket extends JavaLanguageParser {
    public void nextToken(RuntimeEnv env, StreamTokenizer stok) {
        if (OpenBracket.list ==null)
            throw new ParseException("mismatched brackets");
        env.pushObjectOntoStack(OpenBracket.list);
        OpenBracket.list.clear();
        OpenBracket.list == null;
    }
}

Lang.defineNewKeyword("[", new OpenBracket());
Lang.defineNewKeyworkd("]", new CloseBracket());

Then writing List foo = [1 2 3 bar] would yield a new ArrayList populated with 3 Double objects and a string. Even with my friendly psuedo-code it’s a lot more work, but to actually do this is impossible.

I assume that this is what folks like Paul Graham mean when they say things like ‘If you re writing a text-editor, you can turn Lisp into a language for writing text-editors. If you re writing a CAD program, you can turn Lisp into a language for writing CAD programs’ and it strikes me as an amazingly powerful concept.

I think I really like this language.

Java Help

| | Comments (0)

I had a look at the Java Help API today, hoping to use it in an application that I’m writing, alas no. Despite claiming to be interface based, and coming with a reference implementation from Sun, what we now call the service provider pattern, it’s irrevocably tied to Swing. This means that you couldn’t use it to say, provide a help system on an interactive web based system, or an SWT based client side app, which is what I’m interested in.

Sun seem to be more interested in pushing their own ideas onto others than in producing a solid solution. Here’s hoping version 3 of the API solves this, but don’t hold your breath.

Objects have Failed

| | Comments (0)

Ned Batchelder had a pointer to this article by Richard Gabriel entitled ‘Objects have Failed’. As usual Richard has some excellent points, but there are a couple of things that irk me about the piece.

About the failure of reuse: it hasn’t. Failed that is. In fact, reuse has been very successful. A single example makes this abundantly clear: the Java class libraries. I think that this idea that reuse has failed comes from some of the over hyped rhetoric that was bandied around in the early days of OO, but this is like saying that the Internet has failed because it didn’t fulfil the dreams that people talked about at the height of the dot com boom.

The Feyerabend Project gets a mention again. Some valid points, but I don’t really have time for a project that so far just seems to be a list of ‘things we do not like’. When (if?) it finally produces some concrete proposals on how to imporove things then I’ll take notice.

A Modest Proposal

| | Comments (0)

Seth: How about this (it was the first thing that came to mind) - ‘Create a desktop operating system that allows a single support operator to maintain 10,000 user wokstations.’ There are certainly huge implications for ease of administration and scalability there, but probably even more so for ease of use. Hell, it’s probably not even a realistic target, what with human nature and all.