Modal is a beautiful term-rewriting system. While ed(1) is ugly and stateful. I wondered if I can marry these and learn Modal by writing ed(1) in it as I already did, more than once. Re-implementing ed(1) is fun!
Fetch Devine Lu Linvega's latest Modal and run
modal ed.modal
a
hello
p
=> helloSupported commands:
- q: quit
- a: append text (next prompt) as a new line after the current one
- i: same, but before the current line
- p: print current line
- d: delete current line
-
- and +: to move to next or previous line
- j: join the contents (=words) of this line and the next ones
- e: swap the current line contents with the contents of the next one
- =: Get current line number, in unary.
- . iiii: Move to i-th line, in unary.
- I'm using a
>cursor for current line marking. With it, it's easy to match anything and everything around the cursor, be it for counting (=) or modification. - I introduced a swap/
exchange command just because it was extremely intuitive with this notation. - I used a
Buffertype tag to avoid premature command reading when processing lines. After the processing is done, I rebuild the buffer, put aBuffertag on it, and the editor is ready for new commands. Neat trick that made me appreciate type tags that Devine's wiki was suggesting! - I like arbitrary length lists and use them for e.g. line contents. But Modal doesn't make it easy working with lists, preferring tuples and conses instead. Which makes sense, but it still puts me off.