ToFunction
One string, a list of rules, and a run that goes round the list until the string stops changing.
EsolangerII, 2026 · Turing complete: unknown · ●○○ easy · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
EsolangerII made ToFunction in 2026, after Thue. There are three statements and one variable, a string. The rules rewrite it in passes called terms. In a term every rule gets its turn, from the top of the list down. So the order of the rules is the program. Three rules that turn x into z, y into x and z into y swap x and y every term; the same three rules in another order give x back each time.
The machine
| Statement | Does |
|---|---|
define "from" => "to"; | Add a rule |
input "text"; | Set the string |
limit "text"; | Stop when the string equals this |
// ... | A comment |
A rule finds its pattern from the left, replaces it, and looks again from just after what it wrote. So x into xx doubles the x's once per term instead of forever, and En into E turns Enn into En in the first term and E in the second. The run stops at a limit, after a term that changed nothing, or after 1000 terms, and prints the string.
This follows the Python interpreter in the specification. Its text about steps and terms says a rule starts again from the left after each replacement, but the specification's own Duplicator and Dotmaker only work the other way. In this implementation every limit counts, as the Multiplication example needs; the Python kept only the last one.
Example
Addition in unary.
Addition in unary. The digits become x's, the plus sign goes, and three x's become a 3. The second term changes nothing, so the run stops there.
The specification's own Addition counts down with spaces before an E as a timer and stops at 3E. Its Multiplication of 3 by 4 stops at 12E after three terms.
Patterns it teaches
- String rewriting: rules applied in a fixed order, a pass at a time.
Further
See also
String-rewriting paradigm
Write your own in Run Convert a program from ToFunction
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: tofunction.
Command line
shib run tofunction -e 'define "En" => "E";
input "Enn";'shib manual tofunctionSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/tofunction.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org