Tetanus
One regular expression, applied over and over until it no longer matches.
Poolala, 2022 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
Poolala made Tetanus in 2022 and named it after its design, which the specification compares to surgery with a rusty hacksaw. A program has three parts. The first line is a regex, the second line is a replacement, and every line after that is the data string. Each round replaces all matches of the regex in the data, and the run ends when the regex finds nothing.
Read the story
Input and output hang off the groups of the regex. A ~ written right after a group reference in the replacement prints that group, and a ` adds a line of input to the end of the data. A mark only acts when its group took part in the match, so the alternatives of the regex work as the branches of an if.
The machine
| In the replacement | Does |
|---|---|
\1 to \99, \g<name> | The text of a group, empty when it took no part |
\3~ | Also print group 3, with nothing after it |
\3` | Also add a line of input to the end of the data | |
\n \t \\ | A line feed, a tab, a backslash |
The regex is Python's. Its $ also matches before a final line feed, and (?s) at the start lets . match a line feed too. The marks are taken out of the replacement before the first round, and they read the groups of the first match in each round.
Example
The data is Hello, world!.
The data is Hello, world!. The first round prints it and puts ! in front, and then ^(H.+) no longer matches.
The truth machine starts from !. The first round reads a line, and the next prints it when it is 0. On 1 the data stays !!1, so it matches again and prints 1 forever.
The quine ends with a line break. Its data is its own first two lines. A round prints the data and adds a !, and a second ! stops the regex, so the data is printed twice.
The specification also has a cat, a palindromic quine and a program that runs Bitwise Cyclic Tag, which makes Tetanus Turing complete. That program prints the data string after each step. Given the program 0 and the data 101, it prints 101, 01 and 1, then an empty line for the empty data string, and stops.
Patterns it teaches
- String rewriting: one rule, applied everywhere at once.
- Quine: the data carries the program, and printing it twice gives the source.
- Tag systems: Bitwise Cyclic Tag in one regex.
Further
See also
String-rewriting paradigm
Write your own in Run Convert a program from Tetanus
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: tetanus.
Command line
shib run tetanus -e '^(H.+)
!\1~
Hello, world!'shib manual tetanusSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/tetanus.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org