ONE WAY
Two stacks, and values can only travel one way between them.
DigitalDetective47, 2022 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 9 known programs · Test method
Run it
The idea
DigitalDetective47 made ONE WAY in 2022. The specification asks for the name to be shown as an image, or else in capitals. Values live on two stacks. flip moves the top of the primary stack onto the secondary one, and nothing ever moves a value back. Commands work on the primary stack, except inside a second block, where every one of them works on the secondary stack instead.
Read the story
Numbers are exact fractions of any size. 0.1 is stored as one tenth, so 0.1 and 0.2 make exactly 0.3, which is the first mandatory test case.
The machine
One command per line. A block command takes the lines indented two spaces deeper as its block.
| Command | Does |
|---|---|
push x | Push a literal such as true, 9/7, 0.1, "text or a type |
add subtract multiply divide | Pop a, then b, and push a op b |
greater less equal | Compare |
and or not | Logic on bools |
concat len split | Join, measure or split strings |
chr ord repr eval | Convert between numbers, characters, values and their text |
dupe drop typeof | Copy, drop, or push the type |
flip | Move the top value to the secondary stack |
input print | Read a line, print a string |
random | Pick a random step between two numbers |
if else while | Pop a bool and run the block |
second | Run the block on the secondary stack |
There are four types, bool, num, str and type. A string starts at its quote mark and runs to the end of the line, so it has no closing quote. The order of operands matters, as a is the value on top. A wrong type or an empty stack stops the run where it happens. A badly formed line stops the program before it starts.
Example
The mandatory test cases.
The mandatory test cases.
The last one prints its closing quote mark, because the string runs to the end of the line.
The reverse cat splits a line into characters, first character on top, and flips them one by one onto the secondary stack, which turns them round. A type value at the bottom of each stack marks where to stop.
The binary to unary program stops one digit early, so 110 gives six stars but 101 gives four.
Patterns it teaches
- Stack machines: two stacks and a one way street between them.
Further
See also
Stack-based
Write your own in Run Convert a program from ONE WAY
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: one-way.
Command line
shib run one-way -e 'input
print' --input 'cat'shib manual one-waySource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/one-way.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org