(This post was retconned from one I wrote in 2019.)
I've been building built a text editor in my programming language Mu.
The language is a little unconventional. It is purely statement-oriented, like Assembly or Basic. Every statement has just one operation, and its arguments have to be variables or literals.
The editor is a little unconventional. It is built up out of layers (1, 2, 3, 4, …) arranged so that layer 1 will build and run and pass any tests defined in it. Similarly, so will layers 1+2, 1+2+3, and so on.
Later layers add to the code of earlier layers using directives like `before` and `after` on labels. (A statement-oriented language really helps here.) But later layers never modify tests of previous layers. Layers monotonically accumulate constraints.
Layers are really helpful to convey the internals of programs to 12-year old kids. You can try them out for yourself (on Linux or a Mac, with a C++ compiler):
$ git clone https://github.com/akkartik/mu1 $ cd mu1 $ ./mu edit/001-editor.mu
At this point you should see a blank screen, and hitting any key should quit.
Now add a layer:
$ ./mu edit/001-editor.mu edit/002-typing.mu
At this point you see a blank screen and can type letters into it. Lines wrap at a specific column.
Hit `ctrl-c` to exit.
Now add a third layer:
$ ./mu edit/001-editor.mu \
edit/002-typing.mu \
edit/003-shortcuts.mu
Now special keys like tab, backspace and arrows work.
Add a fourth layer.
$ ./mu edit/001-editor.mu \
edit/002-typing.mu \
edit/003-shortcuts.mu \
edit/004-programming-environment.mu
Now you get two text editor windows, side by side. You should be able to position the cursor in them using the mouse, and type on either side.
Again, hit `ctrl-c` to exit.
In this manner you can add more layers and see the entire teaching environment come gradually online. You can also run tests with each subset and see the number of tests gradually grow:
$ ./mu test edit/001-editor.mu .......... $ ./mu test edit/001-editor.mu \ edit/002-typing.mu .................................... $ ./mu test edit/001-editor.mu \ edit/002-typing.mu \ edit/003-shortcuts.mu ...............................................................................................................................
Since each combination is internally consistent, kids can tinker with just the first layer by itself, spending as much time as they want to understand how it works. Once they feel confident they can add the next layer. Or they may just be using the text editor but dig into a specific layer when they want to say add a hotkey for themselves.
Comments gratefully appreciated. Please send them to me by any method of your choice and I'll include them here.