esolang

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

Expected: 210

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 insideCommand
1Add 1 to the cell
3Subtract 1
5Move the pointer right
7Move the pointer left
9Print the cell as a character
11Print the cell as a number
13Read a character
15Read a number
17While the cell is not 0, run what is inside the next group
19If the cell is not 0, skip the next group
21While the cell is 0, run what is inside the next group
23If the cell is 0, skip the next group
25, 27Stop

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.

Expected: ok

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

  1. Print A, which is 65.
  2. Read a character and print the next one in the alphabet.
  3. Hard: TIO's hello world is about 60 lines. Write a shorter one.

Further

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 return

Source

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