Thutu
Thue with regular expressions and indented blocks. The whole state is one string.
ais523, 2007 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
ais523 released Thutu in 2007. It grew out of Thue, where a program is a list of string replacements. Thutu makes each side a regular expression and adds control flow. Thue picks its rules in any order; Thutu runs them top to bottom and groups them into blocks that repeat until nothing in them fits any more.
Read the story
Input and output are part of the string too. The program cannot print or read. It only leaves markers in the string, and between passes the interpreter acts on them.
The machine
The main string starts as =1.
| Line | Does |
|---|---|
/regexp/replacement/ | Replace the first match, then go back to the start of the block |
/guard/regexp/replacement/ | The same, only if the guard matches too |
/guard/< /guard/> | Go back to the start of the block, or leave it |
/guard/@ /guard/* | Open a block, entered when every guard matches |
/guard/^ /guard/! | Open a block, entered when no guard matches |
. | Nothing; used to close a block |
A block is the lines after its marker that are indented further. After a replacement, @ and ^ blocks start again at their first line, while * and ! blocks go back to the marker and test its guards again. The whole program is one @ block.
When the program block ends, the text before the first =x is printed and removed. If =9 is in the string the program stops. If not, one line of input plus =x goes in front of the string, or =9 at the end of the input, and the program runs again. Special characters are escaped with =: =n is a newline, =q is = itself, and = before any punctuation stands for that character.
Example
The string =1 becomes the greeting, an escaped newline, =x to print it and =9 to stop.
The string =1 becomes the greeting, an escaped newline, =x to print it and =9 to stop. The punctuation in the greeting is fine, because only an = in front makes it an escape.
The second rule swaps a b with the c after it, using the groups of its regexp.
A program that does nothing is a cat without the newlines. Each line read goes in front of the string with =x after it, so the next pass prints it.
Patterns it teaches
- String rewriting: the program is a set of rules over one string, like Thue and ///.
- Turing completeness: an Underload interpreter has been written in it.
Try this
- Print your name followed by a newline.
- Print every input line twice.
- Hard: reverse each input line.
Further
- esolangs.org/wiki/Thutu
- The Esoteric File Archive, with ais523's compiler to Perl
See also
String-rewriting paradigm
Write your own in Run Convert a program from Thutu
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: thutu.
Command line
shib run thutu -e '.' --input 'ab
cd
'shib manual thutuSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/thutu.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org