RETURN
Only round brackets. What a group does depends on how many groups it holds.
Ben Russell · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Ben Russell made RETURN, his third language. A program is nothing but ( and ); every other character is a comment. Its idea is that commands are empty functions that call other empty functions, and a command is chosen by how many functions pass through it. In practice that means counting: a group holding one group adds 1, a group holding three subtracts 1, and so on.
Read the story
Underneath it is brainfuck: a tape of byte cells, a pointer, and loops.
The machine
A group first runs the groups inside it, in order, and then does its own command. The command is the number of groups directly inside it.
| Groups inside | Command |
|---|---|
| 1 | Add 1 to the cell |
| 3 | Subtract 1 |
| 5 | Move the pointer right |
| 7 | Move the pointer left |
| 9 | Print the cell as a character |
| 11 | Print the cell as a number |
| 13 | Read a character |
| 15 | Read a number |
| 17 | While the cell is not 0, run what is inside the next group |
| 19 | If the cell is not 0, skip the next group |
| 21 | While the cell is 0, run what is inside the next group |
| 23 | If the cell is 0, skip the next group |
| 25, 27 | Stop |
Every other count does nothing, which is useful: a group of ten (()) adds 10 and then does nothing itself. The empty group () holds no groups and does nothing either.
Example
Three (()) set the cell to 3.
Three (()) set the cell to 3. The group of 17 loops over what is inside the next group: a subtract and a print as a number. So it prints 2, 1 and 0, then the cell is 0 and the loop ends.
Read a character, print it, twice.
Patterns it teaches
- Turing tarpit: brainfuck's commands, spelled as counts of brackets.
- Encoding tricks: nesting does double duty, since the groups inside a command run before it. Ten
(())inside one group add 10 and pick a command that does nothing.
Try this
- Print
A, which is 65. - Read a character and print the next one in the alphabet.
- Hard: TIO's hello world is about 60 lines. Write a shorter one.
Further
- esolangs.org/wiki/RETURN, with Ben Russell's Python interpreter
See also
Also in Turing tarpits
Write your own in Run Convert a program from RETURN
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: return.
Command line
shib run return -e '(())(())(())(()()()()()()()()()()()()()()()()())((()()())(()()()()()()()()()()()))'shib manual returnSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/return.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org