Michael Weber: Random Bits and Pieces

...Please don't assume Lisp is only useful for Animation and Graphics, AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor applications, Expert Systems, Finance, Intelligent Agents, Knowledge Management, Mechanical CAD, Modeling and Simulation, Natural Language, Optimization, Research, Risk Analysis, Scheduling, Telecom, and Web Authoring just because these are the only things they happened to list.

Kent M. Pitman

Lisp Logo (by Conrad Barsky)

Some time ago, I translated Gregor Kiczales' Tiny-CLOS to Common Lisp and Java: MW-TINY-CLOS and jCLOS.

The Common Lisp port is probably not very interesting, this was mostly a warm-up exercise. Only when I was mostly finished, I found Kiczales' original CL (back?)port.

For jCLOS, package jclos contains all functionality. The main method contains some straight-forward example code, which creates an object with two slots x and y, an instance, and a method on the print generic function.


public static void main(String[] args) {
    System.out.println("JCLOS booted.");

    CLOSInstance POS = defineClass(null, null, 
            Arrays.asList(new DirectSlotDefn[]{
                    new DirectSlotDefn(Symbol.intern("x")),
                    new DirectSlotDefn(Symbol.intern("y"))
                }),
            Symbol.intern("<pos>"));
    
    System.out.println(POS);

    CLOSInstance pos = make(POS);
    pos.setSlot(Symbol.intern("x"), 42);
    System.out.println(pos.slot(Symbol.intern("x")));

    CLOSInstance print = makeGeneric();
    addMethod(print,
            makeMethod(Collections.singletonList(OBJECT),
              new StdCallable() {
                  @Override
                  public Object apply(Object[] args) {
                      System.out.println("'" + args[1] + "' is an OBJECT!");
                      return null;
                  }
              }));
    /* ... */
    print.call(POS);
    print.call(pos);
}

I find it quite self-evident that Java is sorely missing some kind of facility for syntactic abstraction. The Java camp appears to disagree, and as Dan Weinreb reports from ILC2009, there are even Lispers thinking that macros are a net drawback!

Regarding jCLOS, I have some ideas what to do with it. However, this might take a while. Short-term, the next step should be to simplify the current implementation as much as possible, for example by getting rid of symbols and keyword arguments. Also, the poor-man's closure objects could probably benefit from some clean-up. (Incidentally, perhaps I should switch to Javascript, just for its support for anonymous functions.)

Some more interesting changes involve the implementation of jCLOS slots (taken over from Tiny-CLOS) in terms of fields. Other/better approaches are known for quite a while:

Shigeru Chiba, Gregor Kiczales, John Lamping: Avoiding Confusion in Metacircularity: The Meta-Helix. ISOTAS 1996: 157–172.

Generally, a cleaner way to avoid meta-stability and circularity issues is also on my list of things to look into.

I also remember a posting by Scott McKay about class slots versus accessors, which is probably also worth following up on (in particular in combination with CHANGE-CLASS like functionality).