2sable
05AB1E with a single input, so a program that needs two copies of it gets the same line twice.
Adnan · Turing complete: unknown · ●●○ moderate
Tested with 8 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
2sable is a golfing language by Adnan, known on GitHub as Adriandmen, made from 05AB1E. The name comes from two and usable. Most commands are the same one-character commands as in 05AB1E. The difference is the input. When a command needs a value and the stack is empty, 2sable reads the first line of input, and after that it hands out that same line every time. So * squares the input instead of asking for a second one.
Read the story
The reference interpreter is one long Python file, 2sable.py in the repository Adriandmen/2sable. Its README says the project is abandoned. This implementation follows the source.
The machine
One stack of Python values. A number literal stays text until arithmetic reads it, so 12S splits the text into ['1', '2']. A command that fails is skipped and the program goes on with the next one.
When the program ends without printing, the whole stack is printed with nothing between the items. That is unlike 05AB1E, which prints only the top.
| Command | Does |
|---|---|
"…" | A string; the last closing quote may be left off |
+ - * / % m | Arithmetic and power; / always gives a float |
n > < | Square, add one, take one |
L Ý | The list 1 to n, 0 to n |
O P J g R S | Sum, product, join, length, reverse, split into characters |
D s ) | Duplicate, swap, wrap the stack in a list |
, = ? | Print with a newline, print and keep, print without a newline |
F v … } | Loop with N from 0, loop over a list with y |
i … ë … } | If the top is 1, else |
Example
Both are from the README.
Both are from the README. * pops twice from an empty stack and gets 7 both times. n+ squares the input and then adds the same input once more.
The last one prints both items of the stack.
This implementation is a subset. The two-character commands, the endless loop [ and the compressed strings stop the run with a reason.
Patterns it teaches
- Code golf: one input reused forever saves the bytes that would copy it.
- Stack machines: an empty stack is a request for input.
Try this
- Print the cube of the input.
- Print the sum of 1 to n, where n is the input.
- Hard: print yes if the input is 1 and no otherwise.
Further
- The reference interpreter, in Python, with Info.txt listing every command
- Related: 05AB1E
See also
Also in Golfing
Write your own in Run Convert a program from 2sable
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: 2sable.
Command line
shib run 2sable -e '*' --input '7'shib manual 2sableSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/2sable.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language