esolang

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

Expected: Hello World!

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

OperatorDoes
\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 bKeep the first, or the second
\E c a ba if c is not empty, else b
\NThe empty string
\= \& \| \!Equal, and, or, not; 1 or empty
\+ \- \* \/ \%Arithmetic on integers
\I \MRead a character or a number
\O xPrint 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.

Expected: Hello World!

The 0th | stands before the start and there is no first, so the cut is the whole program.

Expected: \O\C\|.
Expected: 42.

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

Further

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 leszek

Source

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