I've heard that S-expressions can be represented as trees; for example (f 1 (g 2) 3)
as
.
. . . .
f 1 . 3 [first level]
g 2 [second level]
Is there an editor (preferably free) for editing this kind of structure directly? This would
S-expressions represent a tree, not the other way around. Your example, formatted with newlines:
(f 1
(g 2)
3)
It represents the following cons tree:
+---+---+ +---+---+ +---+---+ +---+---+
--->| f | ----->| 1 | ----->| ¦ | ----->| 3 |NIL|
+---+---+ +---+---+ + ¦ +---+ +---+---+
v
+---+---+ +---+---+
| g | ----->| 2 |NIL|
+---+---+ +---+---+
This is at the same time the actual abstract syntax tree of the program—something that compilers for other language families have to construct from intricate rules.
For editing, the parentheses are all you and your editor need to operate on the tree level. In Emacs it is paredit-mode, but I guess that other editors have similar utilities or plugins.
As far as I know (and as the Wikipedia article confirms), structure editing was used in Interlisp-D. I am not aware of any structure editor for Common Lisp widely in use today, but maybe there is something I don't know about. There is an example on Pascal J. Bourguignon 's site you may want to play around with. (I didn't take a closer look at it) I did, however use something similar for XML in Oxygen some time ago.
(Also, I don't think the reason Interlisp used this had anything to do with getting rid of the parentheses, and there might be problems with comments, for example.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With