05AB1E
A stack of strings, more than 250 one-character commands, and input that turns up by itself when the stack runs dry.
Adnan · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 10 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
05AB1E was made by Adnan, known on GitHub as Adriandmen, for the code golf site. The name can be read as osabie, osable or usable. A program is a row of single characters, each one a command. It is one of the most used golfing languages, next to Jelly and CJam.
Read the story
Two habits make programs short. When a command needs a value and the stack is empty, the next line of input is read in its place. And when the program ends without printing, the top of the stack is printed. So the empty program is a cat, and LO sums 1 to n.
The current interpreter is written in Elixir. An older one in Python still runs on Try It Online as 05AB1E (legacy). This implementation follows the Elixir source.
The machine
One stack. Number literals stay text until arithmetic reads them, so 1 2) is the list ["1", "2"] while 2L is [1, 2]. Most commands map themselves over lists, so 5L> adds one to each of 1 to 5.
| Command | Does |
|---|---|
"..." 'a „ab | A string; the last closing quote may be left off |
+ - * / % m | Arithmetic and power; / always gives a float |
L Ý | The list 1 to n, 0 to n |
D s Ð Š ) | Duplicate, swap, triplicate, rotate three, wrap the stack in a list |
O P J g R S | Sum, product, join, length, reverse, split into characters |
, = ? | Print with a newline, print and keep, print without a newline |
F v [ … } | Loop with N from 0, loop over a list with y, loop forever |
i … ë … } | If the top is 1, else |
ε ʒ Σ … } | Map, filter, sort by |
# | Break out of a loop when the top is 1 |
] | Close every open block |
Example
The string runs to the end of the program and is printed at the end.
The string runs to the end of the program and is printed at the end.
L finds the stack empty, reads 10 from the input and makes the list 1 to 10. O sums it.
F loops five times and N, prints the loop counter each time.
S splits the literal into characters. They are strings, so the list prints them in quotes.
This implementation is a subset. It has the commands above and about a hundred more, and stops with a reason on the rest, such as the compressed strings that look words up in the interpreter's own dictionary.
Patterns it teaches
- Code golf: implicit input and output save the bytes every program would spend on them.
- Stack machines: an empty stack is not an error but a request for input.
- Concatenative: a program is commands applied to one stack in a row.
Try this
- Print the squares of 1 to 10 as a list.
- Print the even numbers below 20, one per line.
- Hard: print the input reversed if it is longer than five characters, else unchanged.
Further
- esolangs.org/wiki/05AB1E
- The reference interpreter, in Elixir, with docs/info.txt listing every command
- Related: CJam, Jelly
See also
Golfing languages
Stack-based
Write your own in Run Convert a program from 05AB1E
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: osabie.
Command line
shib run osabie -e 'R' --input 'hello'shib manual osabieSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/osabie.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org