4 ms·
> Manipulating graphs, er, graphically, will not give you some sort of magical get-out-of-jail-free card against syntax errors or undefinable behaviour etc. It
by chriswarbo 10y ago
> Manipulating graphs, er, graphically, will not give you some sort of magical get-out-of-jail-free card against syntax errors or undefinable behaviour etc.
It does prevent some errors, like malformed structures. For example, the following Lisp:
(defun (square x (* x x))
Or the following C:
void square(int x {
return x * x;
Or the following Ruby:
while $i < $num do
puts "Inside the loop i = #$i)
$i +=1
These sorts of things can occur when manipulating programs at the character level, but they're inexpressible at the level of parse trees/graphs. Balancing parentheses, braces, quotation marks, begin/end, etc. is exactly the sort of task that machines can automate away.
The idea of a general tree editor is not to prevent syntax errors, undefined behaviour, etc. because those are properties of specific trees, e.g. the parse trees of C programs. A tree editor just edits trees; it doesn't care what those trees represent (that's why the author mentions a plugin mechanism, like Emacs has different modes for editing files written in different languages).
Manipulating programs at the level of parse trees can also be more efficient, less tedious and prevent errors, e.g. see the paredit videos linked in other comments. By analogy, what's the point of a general text editor, when our CPU can already perform arithmetic on bytes? A general text editor doesn't prevent syntax errors, undefined behaviour, etc. Does editing strings of text, rather than numerical bytes, provide expressive power or syntactic clarity that we don't have with high-level languages already?
I also don't think the author was asking for something "graphical" or "GUI" per se; their analogy is with text editors (e.g. Emacs and Vi), which are efficient both in their display and their interaction. A general tree editor wouldn't be based around e.g. drag'n'drop of nodes/edges, in the same way that general text editors aren't based around drag'n'drop of glyphs in a grid.
General text editors have features for moving to the start/end of a line, for cut/paste up to the next space or linefeed, for highlighting parentheses, for folding/unfolding between sentinel characters, etc. General tree editors would instead have features to move to the root/leaf of a tree, cut/paste sub-terms, fold/unfold expressions, etc. No need to care about the existence of whitespace, linefeeds, indentation, parentheses/delimiters, etc. they can all be handled mechanically.
- kazinator 10y agoWe can have editing methods that are character-based, yet which make those kinds of syntax errors impossible. A trivial example of this are input fields which enforce a lexical format. For instance, we can implement an input field for a floating-point number where you simply cannot type some garbage like "1.E". What happens is that you type "1" (so far so good), then then "1." (still good) and then "1.E" (good prefix, but bad). Since it is a good prefix, the "E" is allowed, but the validator automatically inserts some suffix to make it valid, like 0. So you see "E0". The 0 is selected so that the next thing you type will replace it. But if you type some garbage like Z, it will be rejected; at that point you may only type a + or - sign, or a decimal digit.
- chriswarbo 10y ago> We can have editing methods that are character-based, yet which make those kinds of syntax errors impossible. Your example doesn't work very well, since it's very specific (the author wants "general-purpose"), and I would say it's not actually a "character-based editing method": it has a keyboard-driven UI and a character-based display, but so does NetHack. Instead I'd say your example is a float editor, rather than a 'text editor with syntax rules'. In any case, there is an example which is close to a general-purpose tree editor that's is keyboard-driven with a character-based display: paredit mode in Emacs, as mentioned by other comments. It's implemented exactly like you describe: many keypresses correspond to the insertion of their respective characters, but when that would invalidate the tree structure (e.g. '(' and ')' keys), different actions are taken instead. For example, '(' inserts '()', whilst ')' "steps over" existing ')' characters rather than inserting extra ones. My issues with paredit, as I've written in other comments, are that it's stuck with a single representation of trees as parenthesised s-expressions: there's no way to alter the "view" of a tree, e.g. to a boxes-on-sticks view or a nested-boxes view (whether they're displayed using ASCII art or GUI widgets). It also leaks implementation details, e.g. altering the alignment or indentation of expressions will cause the file contents to change, despite having nothing to do with a tree.