Friday 20 September 2013

Editing and clojure revisited: this time, with structure!

Yesterday I blogged on editing Clojure, and commented that

"So after all that I'm going to talk about how wonderful it is to be able to do structure editing in Clojure, aren't I? No, sadly, I'm not, because (as yet) you can't."

Well, you can now. About tea-time yesterday, fooling around with Clojure, I worked out how the 'source' macro works - it retrieves the source of the function or macro whose name is its argument, by inspecting the metadata tagged to the symbol. So, you can retrieve function definitions. They're retrieved as strings from the file, but the read-string function parses s-expressions from strings, so that isn't a fatal problem. And having found that, a terminal based structure editor was not far away.

OK, it is, as yet, crude. It needs a lot of polishing. And, a terminal oriented structure editor is not what I really want - I want a display editor which pops up in a window (and, related to that, a display inspector, too). That window is almost certainly a web page. However, writing a terminal oriented structure editor proves that it can be done.

There are significant problems ahead. You cannot, in theory, rebind a Clojure symbol, so you cannot in theory compile a new definition for an existing function symbol. But the package system does this, so it is possible. I need to find out how. Indeed, the whole package system would have to be modified significantly to support in core editing. Just writing an editor is only scratching the surface.

But the surface is scratched. There is now a structure editor for Clojure. You can get it here.

No comments:

Creative Commons Licence
The fool on the hill by Simon Brooke is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License