Parentheses only
Nothing but parentheses. The first group takes in the second and rewrites itself, until no rule fits.
Hakerh400, 2020 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Hakerh400 made Parentheses only in 2020. A program is a row of balanced groups, and each group is empty or holds more groups. There is no other symbol. The program runs by rewriting itself, and the state it cannot rewrite any further is the output. Input is written the same way and appended to the source.
Read the story
The specification gives its computational class as unknown.
The machine
A step looks at the first two global groups, the ones not inside any other.
| At the front | Step |
|---|---|
no group, or a lone () | Halt |
() and () | Drop one |
() and a group with content | Swap them |
| a group of one element | Put that element's content in its place |
| a lone group of two or more | Halt |
Otherwise the first group A meets the second group B, and both are removed. The first element C of A is dropped, and the other elements of A take their place, each with C replaced by B. The replacing skips the first element of any group of two or more, and the whole group when that first element is C, which then acts much like a bound variable.
Example
The first is the worked example.
The first is the worked example. A is (()((())())), B is (()()(())) and C is (). Replacing () by B in ((())()) gives ((())(()()(()))), still followed by the last (). One more step of the same kind leaves (()()()), a lone group of three, and the program halts.
In the second, a group of one element opens up into ()(), and one of the two empty groups is dropped.
Patterns it teaches
- String rewriting: the program text is the whole state, and the final text is the output.
See also
String-rewriting paradigm
Write your own in Run Convert a program from Parentheses only
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: parentheses-only.
Command line
shib run parentheses-only -e '((()()))'shib manual parentheses-onlySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/parentheses-only.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org