Acc!!
One variable you can write, loop counters you can only read, and a loop counter that vanishes when its loop ends.
DLosc, 2015 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 6 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
DLosc made Acc!! in 2015 for a Code Golf challenge to build a language that only appears to be unusable. The syntax reads like plain English. The difficulty is in the semantics. The accumulator _ is the only thing a program can assign, so every bit of state has to be packed into one unbounded integer with arithmetic.
Read the story
The first version, Acc!, let a loop counter be read after its loop had ended. That made it too easy, so the second version forbids it.
The machine
| Statement | Does |
|---|---|
expr | Set the accumulator _ to expr |
Write expr | Print the character with code expr |
Count i while expr { … } | Set i to 0, run the body while expr is not 0, adding 1 to i each round |
# text | A comment |
Expressions use unbounded integers with + - * / % ^ and brackets, the accumulator _, the counters a to z of the loops around them, and N, which reads one character each time it is used. Every line of input ends in a newline, the last one too, and N gives 0 after the end.
The reference interpreter turns each expression into Python. So ^ binds tighter than a minus sign in front of it, and / and % round toward minus infinity.
Example
The last program lowercases its input.* is 1 exactly when the code is between 65 and 90, a capital…
The last program lowercases its input. (_/65)*(90/_) is 1 exactly when the code is between 65 and 90, a capital letter, and 0 otherwise, so 32 is added only to capitals. Arithmetic like this replaces every if.
Patterns it teaches
- Turing tarpit: loops that count and one variable are enough, but only just.
- Encoding tricks: esolangs.org's digit counter keeps ten counters in base 3 inside the accumulator, next to the last character read.
- Turing completeness: an unbounded accumulator can hold a whole tape.
Further
- esolangs.org/wiki/Acc!!
- DLosc's interpreter, in Python
See also
Also in Turing tarpits
Write your own in Run Convert a program from Acc!!
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: accbb.
Command line
shib run accbb -e 'Count i while 10-i {
Write 48+i
}'shib manual accbbSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/accbb.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org