BracketsLang
Four kinds of brackets, empty or full, and every full pair keeps its own accumulator.
PoetLuchnik, 2021 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
PoetLuchnik made BracketsLang in 2021 to show that brackets are better than the indentation of Python. Only the eight bracket characters are code. Everything else is a note, so a program carries its own comments without any comment syntax.
Read the story
An empty pair is an atom that works on the accumulator of the block around it. A pair with code inside is a block. It starts with its own accumulator at 0, and when its code is done it uses that value as an address, a test or a count for its parent. The whole program is itself a { } block, so it repeats until something breaks out of it.
The machine
| Pair | Empty | With code inside |
|---|---|---|
( ) | Print the accumulator | Store the parent's accumulator at RAM[a] |
[ ] | Add an input byte | Add RAM[a] to the parent's accumulator |
< > | Set it to 0 | If a is not 0, end the parent block at once |
{ } | Add 1 | Repeat until a < > inside ends a run, then take a from the parent |
In the table, a is the block's own accumulator when its code ends. The accumulators and the 256 cells of RAM are bytes. Every run of a block starts its accumulator at 0 again. At the end of the input [] adds -1, as getchar() in C would.
Example
The Hello World program (almost).
The Hello World program (almost). It counts to 72 for H, takes 3 away with a loop that runs once, and ends with <{}>, whose accumulator of 1 breaks the program's own loop.
Eight {} make 8 and (<>) stores it at address 0. Seven [<>] add it back, which gives 64, and one more {} gives 65.
The Alphabet program keeps a count of 26 at address 0 and the letter at address 1. Each run of the big loop loads the letter, prints it, adds 1 and stores it. The <{ }> under it counts address 0 down. While the count is not 0 its inner < > ends the inner loop with 0. At 0 the loop ends through <{}> with 1 instead, the outer < > is left with 255, and that breaks the big loop.
The cat, []()<>, has no escape. It echoes the input and then prints byte 255 until it is stopped.
Patterns it teaches
- Turing tarpit: eight characters, and the notes around them are free.
Further
See also
Cell-based
Write your own in Run Convert a program from BracketsLang
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: bracketslang.
Command line
shib run bracketslang -e 'r0 = 26
{}{}{}{}(<>)[<>][<>]{}(<>)[<>](<>)
65
{}{}{}{}{}{}({})[{}]{}
r1 = 65
({})
infinity loop
{
load r1
[{}]
print r1
()
+1
{}
store r1
({})
if --r0 == 0 then break
<{
if --r0 != 0 then break
<[<>]{{}<{}>}(<>)>
+1
{}
<{}>
}>
}
end of program
<{}>'shib manual bracketslangSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/bracketslang.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org