An editor for composed programs
tratt.net
tratt.net
In practice, it's very easy to start using and very powerful... but requires using Lisp. It'll seem odd if you're not regularly a Lisp user.
Happily, this idea can generalize well enough to distinctly non-Lisp languages. Structured Haskell mode[2] does this for Haskell, which has a less regular and sparser syntax than s-expressions. The documentation has a bunch of handy animations showing the various features, giving you an idea of how it works without having to install it yourself.
This doesn't address the meat of the blog post—composing languages and grammars by taking advantage of structured editing—but it shows that the necessary foundation is possible with a perfectly normal text editor. It would be interesting to see if some of the ideas from Eco could be added to structured editing modes like this without requiring you to use an external, self-contained editor.
[1]: http://www.emacswiki.org/emacs/ParEdit
[2]: https://github.com/chrisdone/structured-haskell-mode
Also, here's a great video of Paredit in action:
In your example, the language composition is smooth because there's only one language there: Lisp. HTML has capitulated.
In different environments, different syntaxes show strength. What happens if you misplace a ) vs misplacing an </tag> ?
You cannot "misplace" a closing parenthesis, at best you can have too many of them not enough. Of course, you can enclose the wrong amount of material, but to see what is being enclosed, you just need parenthesis matching support in the editor. This is more common than XML tag matching support. E.g.
http://stackoverflow.com/questions/500989/jump-to-matching-x...
Currently I am using it a lot to write React's JSX which combine javascript and XML.
That's... a bit unfair characterization of Emacs. It is built for extensibility, built as a development platform for Elisp packages - and that's not how most editors are designed and coded.
Anyway, it's probably completely possible to adopt many or most proposed features into Emacs but it could be prohibitively hard to adopt them into some other editors.
This is quite an amazing article in that the author really "gets" Lisp and yet at the same time doesn't get it.
(It isn't mentioned; don't waste time looking.)
If you admit you're already thinking in terms of that tree structure already, just freakin' use it instead of this charade of encoding into in some completely rearranged way that has to be unraveled back to what you were originally thinking of anyway (or something else).
There are some difficulties in this, of course. Sometimes I don't think in terms of trees of information. This is relatively rare, though.
ps: I rarely hear about http://en.wikipedia.org/wiki/L_Peter_Deutsch but his work is impressive.
(But on larger machines in the 70s I get the impression Interlisp stayed with structure-editing for its advantages, not just inertia. It was killed off by Common Lisp which owed more to the east-coast Lispers who gave us Emacs.)
I thought emacs text buffer genes came from being implemented on and for *nix ..
I had to write a library to transform JSON from one shape into another, carrying over the values but placing them in different nodes on a new tree. I found that thinking in terms of tree transformations was incredibly hard. The way I solved it was by flattening the JSON, transforming the flattened version, and when I'm done, inflating it back up.
In other words, working with the simpler, "2D" version of a JSON was much simpler than its "3D" tree structure, and writing flatten/unflatten independent from the transforming code was a nice modularity bonus.
It's really all about decomposing the problem and solving its parts.
It sounds like you could have benefited from a way to express pattern matching using JSON syntax, for destructuring a JSON object, and to represent the synthesis of new JSON using a "JSON quasiquote".
E.g. Lisp transformation with classic destructuring-bind and backquote:
(destructuring-bind (a (b (c &rest d) e) f (g h)) some-obj
`((,a ,b) ,c (,@d 1 2 3 ,e) (,f ,g, h)))
There are pattern matching libraries nowadays that do a lot more than destructuring-bind, but it illustrates the basic point.The destructuring-bind macro writes the code to pull apart some-obj according to the tree picture with embedded variables. The backquote syntax generates the code whose evaluation synthesizes the new tree object according to a template, with the values of expressions indicated by , and ,@ substituted and spliced into the template.
It did get me thinking, though, so I appreciate the advice. I'm wondering now how to port that idea to Ruby.
(Why almost: because "destructuring lambda lists" don't support the environment parameter of macro lambda lists!)
http://soft-dev.org/pubs/pdf/diekmann_tratt__parsing_compose...
However in order to compete with text, which has a bountiful number of editors available. You need to beat the programmers favorite editor at writing the program. Doing this given the competition size is incredibly hard.
While I think the has merit at a high level, poor implementation isn't the biggest thing holding back non-text implementations. Being the best editor for everyone has been.
On a related note, is there a reason they didn't go with some form of escaping? Similar to CDATA in XML.
Of interest are languages like Nemerle, which allow you to define additional syntax for the language through macro systems - however, there are dedicated delimiters which can be used to enclose sequences to ensure unambiguity. (Nemerle uses a PEG based parser).
Another interesting approach is taken by Wyvern, which was just posted recently - which uses different indentation levels to disambiguate different languages in the same text file.
What's interesting about Tratt and Diekmann's model (Language Boxes), is they do not specify a storage format - although they use a tree based format in the implementation of eco, one could in theory, spit out plain text in languages like Nemerle and Wyvern - where the editor can do the job of selecting the right escape delimiters for each embedded language - and the result is just a plain text file which can be accepted by the normal compilers, but that's still open for research.
Additionally problem character replacement isn't so bad if it is machine controlled, since it can be more complex and making it human editable isn't a problem since your current format isn't human editable.
Any research at all? I'm curious: what it is that's unworkable about text in your view?
Other people spending money to figure out if an alternative idea will work is good for me.
> what it is that's unworkable about text in your view?
Nothing, it just feels like a local maximum. Typing is incredibly efficient, so I don't think it is going anywhere.
There are plenty of ways of showing that in a certain situation non-text can be more efficient, so I believe there is a way to introduce non-text that can make the general case more efficient.
http://orgmode.org/manual/Working-With-Source-Code.html#Work...