esolang

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

Expected: Hello, World!

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.

CommandDoes
"…"A string; the last closing quote may be left off
+ - * / % mArithmetic 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 SSum, 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.
Expected: 49
Expected: 20

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.

Expected: 55
Expected: [1, 2, 3, 4, 5]
Expected: 12

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

  1. Print the cube of the input.
  2. Print the sum of 1 to n, where n is the input.
  3. Hard: print yes if the input is 1 and no otherwise.

Further

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 2sable

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/2sable.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language