ShortO
Everything you write is printed. The program lives in the gaps you cut with $.
MasterWoodie, 2023 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
MasterWoodie made ShortO, short for Short Output, in 2023 to make printing text easy. A file of plain text is a program that prints itself. To compute, you open a codeblock with $ and close it with ;. Inside it works one stack of numbers and strings.
Read the story
There are no loops. A marker #name; outside a codeblock names a place, and the same #name; inside a codeblock jumps back or forward to it. The > command skips the next few instructions when a value is true, and that is the only way to choose.
The machine
Outside a codeblock.
| Char | Does |
|---|---|
| any other | Print itself |
$ ... ; | A codeblock |
#name; | A marker |
\ | Print the next character as it is |
// | Comment out the rest of the line |
Inside a codeblock, with a taken from the top and b under it.
| Command | Does |
|---|---|
12 1.5 "text" | Push a number or a string |
#name; | Jump to the marker |
+ - * / % | Arithmetic on b and a; strings join, shrink and repeat |
= ! | & | Compare, not, or, and |
~ ' S N | Convert to a number, a character, a string or character codes |
, X ^ v l | Print, drop, repeat, reverse, stack size |
> | Skip that many instructions if the value under it is true |
. _ : | Read a character, a line or a number |
D C | Take characters back from the output; clear it |
T L ? ° | Type, length, random, floor |
0 and the empty string are false. The specification's table says = pushes 1 when a is greater than b. Its FizzBuzz stops at once unless it is the other way round, so this implementation pushes 1 when b is greater, as the program needs.
Example
The truth machine reads a character and makes it a number.
The truth machine reads a character and makes it a number. On 1 the > skips the jump to end, and the program falls into a loop that prints 1 for ever.
The calculator reads two numbers and an operator. Each test copies the operator, compares it and skips three instructions when it does not match.
The FizzBuzz copies its count in an odd way. It prints the count as a character, takes that character back from the output with 1D and turns it into a number again with N.
The 99 bottles of beer also works. It keeps three copies of the count on the stack, prints two of them and counts down with the third.
Patterns it teaches
- Stack machines: one stack, with text printed around it.
Further
See also
Stack-based
Write your own in Run Convert a program from ShortO
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: shorto.
Command line
shib run shorto -e 'Hello World!'shib manual shortoSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/shorto.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org