Pyfun
One Python expression in five characters, worked out again and again on a list called a.
Turing complete: yes · ●●● hard · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
A Pyfun program uses only a [ ] + <. It is pasted into a small Python 3 loop in the place of one expression. The list a starts as [0], and each turn it becomes the value of the expression. Then its first item says what happens. 1 reads a character into a[1], 2 writes the character a[1], and 3 stops. Anything else does nothing, and the loop goes on.
Read the story
There are no digits. []<[[]] is True, because the empty list sorts first, and []<[] is False. Indexing a list of one with False gives its item back as something unary plus and shifts accept, so +[[]<[[]]][[]<[]] is 1. Every other number is built from that with + and <<.
The machine
| Piece | Python reads it as |
|---|---|
a | The list from the turn before |
[x] [] | A list of one item; the empty list |
x[i] | Item i of a list |
+x | A number, unchanged; True becomes 1 |
x+y | Numbers added, or lists joined |
x<<y | x shifted left by y bits |
x<y | Numbers or lists compared; x<y<z means both comparisons hold |
Whatever Python would refuse stops the run with Python's error. Indexing past the end of a list does, and so does reading at the end of the input, where ord('') fails.
Example
The Hello World is 4,479 characters.
The Hello World is 4,479 characters. It holds a table of 14 states, from [2, 72, 1] for the H to [3] for the end, and picks the next one by a counter in a[2]. The first turn finds a is [0] and goes to [4, False, False], which does nothing but make a[2] exist.
The cat is a table of three states picked by a[0]. After 0 or 2 it reads, after 1 it writes a[1]. Nothing in it ever asks to stop, so it ends where Python does, with ord('') failing at the end of the input.
Patterns it teaches
- Encoding tricks: numbers come out of comparing empty lists.
- Hostile design: five characters of Python, and the 13 characters of Hello World take 4,479 of them.
Further
See also
Also in Hostile
Write your own in Run Convert a program from Pyfun
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: pyfun.
Command line
shib run pyfun -e '[+[[]<[[]]][[]<[]]+[[]<[[]]][[]<[]]+[[]<[[]]][[]<[]]]'shib manual pyfunSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/pyfun.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org