esolang

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

Expected: Hello World!

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.

CharDoes
any otherPrint 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.

CommandDoes
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 NConvert to a number, a character, a string or character codes
, X ^ v lPrint, 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 CTake 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.
Expected: 0

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.

Expected: Calculator: Enter number 1: Enter number 2: Enter operator: (+-*/%): 42

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.

Expected: Fizz Buzz: Enter count: 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz

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

Further

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 shorto

Source

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