Probably a bad idea…

File this one in the category of crazy ideas had while running. I was thinking about my new org-mode plugin that I announced yesterday and how hard it is to write in Emacs Lisp. I was wishing that I could write it in Clojure instead. Now, they're not such different languages – they both are evolutions of McCarthy's original lisp, but Clojure is a much prettier, less crufty language.

Let's look at just one construct in both languages: let. In both languages, this assigns values to variable names locally. In elisp, it looks like:

(let* ((foo bar)
       (baz foo)))

Instead of calling let there, I had to call let*, so that the results of the first assignment were known to the second assignment. There is also a lot of parentheses there. (Unparenthesized variables become automatically initialized to nil I believe. I don't think that's a great idea.) Contrast this with Clojure's let.

(let [foo bar
      baz foo])

To me, that's much more readable.

Clojure's core libraries are also much more readable than most of elisp. It seems to me that elisp was designed in the days where computer usage was charged by the letter and has not been updated since. (Don't get me wrong – I love Emacs and would rather program in elisp than Perl, but it has some warts.)

Maybe not so crazy

Emacs already has a reader that can be used to turn lispy-looking things into lispy data structures. Add some macros on top of that and you might be able to produce a def that's equivalent to Clojure's. Since much of Clojure is written in Clojure (and all of Clojurescript is), defining the Clojure functions might just be a hop, skip, and jump away from that.

Clojure could intern symbols into emacs (with namespaces prepended) and then emacs could use them. Clojure could also call emacs functions directly – any symbol that isn't defined in a Clojure namespace would be tested to see if it exists in emacs.

Probably pretty crazy after all

One of Clojure's big selling points is its concurrency semantics. I don't follow emacs development very closely, but I don't think emacs is going to support any of that any time soon. Also, would it be possible to compile the new language to elisp bytecode? How would recur work?

There are a lot of questions, and here I am working on a plugin for a combination of tools that hardly anyone uses. But everyone has to scratch their own itch as they say.

Totally crazy

Update: As I suspected, this idea won't work: elisp doesn't have reader macros, so the difference in read syntaxes of clojure and elisp would be impossible to express to the elisp reader. Maybe one could write a parser in elisp, but that would probably be slow and hard to do. The idea was only attractive when large parts were already done.

blog comments powered by Disqus