Leszek
No jumps, no loops, no variables and no stack. Each turn the program is replaced by what it says.
Janek37, 2006 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 7 known programs · Test method
Run it
The idea
Janek37 made Leszek in 2006. A program is a row of expressions. A plain character is worth itself, and an operator is a backslash and one more character followed by its parameters. Each turn every expression is worked out and the values, joined in order, become the next program. The run ends when no \O is left, as nothing could be printed any more.
Read the story
The main operator is \C, the cut. \C\$2. is the piece of the current program between the second and the third $. A program keeps its data at its own end and cuts pieces out of itself, so a loop is a program that writes itself back with one thing changed.
The machine
| Operator | Does |
|---|---|
\C\dn. | The text after the nth d up to the next one |
\L\dn. | The length of that cut |
\T a b \G n. ... | Join two values, or n values |
\A a b \D a b | Keep the first, or the second |
\E c a b | a if c is not empty, else b |
\N | The empty string |
\= \& \| \! | Equal, and, or, not; 1 or empty |
\+ \- \* \/ \% | Arithmetic on integers |
\I \M | Read a character or a number |
\O x | Print x |
Integers are written with a dot at the end, so 24 is 24. and 0 is .. Delimiters after a backslash do not count when \C looks for them, which is how \C\.1. can name its own delimiter.
Example
The cut after the first dot runs to the end of the program, so it is the greeting.
The cut after the first dot runs to the end of the program, so it is the greeting.
This one prints one character a turn. It copies its code, drops the first letter after |, prints that letter, and stops when only % is left between the bars.
The 0th | stands before the start and there is no first, so the cut is the whole program.
The 99 bottles of beer program keeps its count between dots and its lines between $ signs. It sings all 99 verses, down to 1 bottle in the singular and No bottles at the end.
Patterns it teaches
- String rewriting: the whole program is rewritten every turn.
- Quine: a cut of the program is the program.
- Self-modifying code: every loop rebuilds its own text.
Further
See also
String-rewriting paradigm
Write your own in Run Convert a program from Leszek
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: leszek.
Command line
shib run leszek -e '\O\C\|.'shib manual leszekSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/leszek.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org