Archive for Clojure

Editing comfort

Emacs is on my long list of things that I love in theory, but in practice have only the most tenuous of grips on. (See also: Go, wine tasting, Fourier analysis. Also, I know I ended a sentence with a preposition. Suck it up.)

So – and I say this with all love and in spite of my new year’s resolution – Eclipse with Counterclockwise? So much easier to use than Emacs with SLIME. Almost certainly less powerful, but for the purposes of learning a language, I do not care.

Comments (520)

Closures in Java (as opposed to Clojure, which… nevermind)

Last time I worked with Java was before my Lisp days (or at least various attempts to get into Lisp), so I’m looking at it again now with a different context. So when I came across this use of an anonymous class in Effective Java (comments removed for brevity – bad practice shut up shut up):

static List<Integer> intArrayAsList(final int[] a) {
    if (a == null)
        throw new NullPointerException();

    return new AbstractList<Integer>() {
        public Integer get(int i) {
            return a[i];

        @Override public Integer set(int i, Integer val) {
            int oldVal = a[i];
            a[i] = val;
            return oldVal;

        public int size() {
            return a.length;

…my first thought was “waaaitaminute… Java has closures?

Now, it took a while for my memory of these things to come back, and a bit of searching to fill in the gaps… it turns out Java doesn’t quite do closures (it doesn’t work with non-final variables because it actually copies them behind the scenes), and at any rate there’s still the whole anonymous class mess instead of first-class functions (which I’ve always found annoying).

Then, it turns out that there’s a proposal to get first-class functions and lambda expressions in Java. And not from some random functional programming fanboy, but taken seriously by Sun and at one point planned for inclusion in Java 7 (it’s now deferred to Java 8).

All of this makes me wonder though… How does Clojure implement closures? Does it have some roundabout way of doing it that could mess up performance in opaque ways? Or is the JVM really that much more flexible than the Java language lets on? Or is Clojure a completely degenerate Lisp dialect?

Apparently I’ve got more reading to do.

Leave a Comment

Java and whatnot

It’s been about six years now since the last time I had a job that involved writing Java. Since then I’ve pulled it out occasionally for toy projects, but that role has been taken over lately by Python (although not for anything heavily numerical).

In the last couple of weeks I’ve started playing around with it again, for a confluence (pun partially intended) of minor reasons:

  • Android. When I got my HTC Hero last year, I’d always planned to dabble in app development, but never got around to it. Now that Tina has a Samsung Galaxy S (a genuinely awe-inspiring phone, by the way), it’s become interesting again; that, and I actually have an idea for a project (more on that later).
  • When I started looking into Lisp, I read a bit about Clojure, a Lisp dialect that compiles to the JVM. At the time, it seemed like a bit of a fringe project, albeit a cool one. Now that I’ve gone through the Common Lisp thing and concluded that its biggest problem is the available compilers, a more modern take on a well-supported platform with solid standard libraries is starting to sound appealling.
  • Other stuff that I won’t talk about yet. Ssshhhh!!!

Leave a Comment