Pico
Two symbols. Every pair of brackets is a call of one Python function, and how deep the calls nest says what they do.
Salpynx, 2020 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Salpynx made Pico in 2020, after Picofuck and the idea of simple translation. The specification defines it with finite state transducers. One turns brainfuck into Pico a character at a time. Another turns Pico into Python, where [ becomes pico( and ] becomes ),. So a Pico program is a tree of nested calls of a single function, and Python runs it from the inside out.
Read the story
The function keeps a flag. The innermost call gives -1 while the flag is clear and 1 once it is set, and each call around it moves the number one step further from 0. A negative number picks an instruction and runs it, and running clears the flag. A positive number only builds a tuple. The start of a loop sets the flag, so everything inside the loop is compiled into tuples, and the loop runs those tuples again and again.
The machine
| bf | Pico | The call it becomes |
|---|---|---|
+ - | [[[]][[[]]]] [[[]][[]]] | pico(-2, 3) adds 1, pico(-2, 2) takes 1 away |
< > | [[[[]]][]] [[[[[]]]][]] | pico(-3, 1) and pico(-4, 1) move the pointer |
. | [[[[[[]]]]][[[]]]] | pico(-5, 3) prints the cell as a character |
, | [[[[[[[]]]]]][[[]]]] | pico(-6, 3) reads a line and keeps its first character |
[ ] | [[][[[]][[]] ]] | pico(-1, (2, 2, ...)) runs the tuples while the cell is not 0 |
With 1 or 2 in place of the 3, the print call writes the cell as True or False or as a number, and the read call takes a line as a boolean or an integer. Cells and the pointer stop at 0 instead of going below it, and they have no top. Input comes a line at a time through Python's input(), so a cat needs each character on its own line, and an empty line reads as 0. Reading past the end of the input stops the program with Python's error.
Example
The cat is ,[.,] through the table.
The cat is ,[.,] through the table. The empty line at the end of the input ends its loop.
Two + and then the print call with 2 instead of 3, which prints the cell as a number.
The Hello World is the usual brainfuck one through the table, 1,262 brackets long, and it prints Hello World!. The specification also runs Daniel B. Cristofani's dbfi, a brainfuck interpreter written in brainfuck, as 4,296 brackets. Fed ,[.,]!It's a cat program! one character per line, it prints It's a cat program!, in about 37,000 steps.
Patterns it teaches
- Turing tarpit: two symbols, with all of brainfuck inside.
- Encoding tricks: the meaning sits in how deep the brackets nest.
- Metacircular interpreter: dbfi runs in it unchanged.
Further
See also
Pico builds on Brainfuck.
Brainfuck derivatives
Write your own in Run Convert a program from Pico
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: pico.
Command line
shib run pico -e '[[[[[[[]]]]]][[[]]]][[][[[]][[]][[[[[[]]]]][[[]]]][[[[[[[]]]]]][[[]]]]]]' --input 'c
a
t
'shib manual picoSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/pico.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org