ShortO

From Esolang
Jump to navigation Jump to search
Short O
Designed by user:MasterWoodie
Appeared in 2023
Memory system stack-based
Computational class Unknown
Reference implementation MasterWoodie Homepage
File extension(s) .sho

ShortO (Short Output, .sho) is designed to easily output text. It was created by user:MasterWoodie in 2023

Description

ShortO is a stack based language, where everything you write is automatically printed to the console
You can define codeblocks in which the logic of the program can be defined
Additionally you can define markers outside of codeblocks, that allow the program to jump to when defining the same marker inside of a codeblock

Data Types:

  • Number: int or float, when writing a number you cannot use - :(, but negative values exist
  • String: surrounded by "


To push data onto the stack, just write the data inside of a codeblock
Since there are no booleans 0 and "" are considered false, every other value true
When a number is too big, it turns into "Infinity"
When a number is too small, it turns into "-Infinity"
When a result cannot be calculated, "N/A" is used Range of numbers depends on interpreter

Features

Outside of Codeblocks:

Command Description
$ Marks the start of a codeblock
# Marks the start of a marker, the followed string defines the markers name
; End a marker or codeblock
\ print next character regardless of special use
// Create a comment for that line

Inside of Codeblocks:

Command Description
# Marks the start of a marker, the followed string defines the markers name
; End a marker or codeblock
\ escape characters in strings
+ Addition: Pop two values a and b, then push the result of b+a; strings concatenate
- Subtraction: Pop two values a and b, then push the result of b-a; if either a or b is a string then the length of that string will be reduced by the number, if both a and b are strings than all the occurrences of a will be removed from b
* Muliplication: Pop two values a and b, then push the result of b*a; if either a or b is a string then the string will be repeated number of times (negative numbers are made positive), if both a and b are strings than "N/A" is pushed
/ Division: Pop two values a and b, then push the result of b/a; if any of those two values are strings than "N/A" is pushed instead
% Modulo: Pop two values a and b, then push the result of b%a; if any of those two values are strings than "N/A" is pushed instead
| Logical OR: Pop two values a and b, if a or b is true push 1, otherwise 0
& Logical AND: Pop two values a and b, if a and b are true push 1, otherwise 0
= Comparison: Pop two values a and b, if a is greater than b push 1, if a is less than b push -1, if they are equal push 0, strings are always considered bigger than number
! Logical NOT: Pop top value, if the value is false push 1, otherwise 0
~ Number Converter: Pop top value, if value is a number, push value, if value is a string, it will be converted into a number and pushed, if the string cannot be converted, "N/A" is pushed instead
' Character Converter: Pop top value, if value is a string, push value, if value is a number, push the corresponding unicode character
, print: Pop top value and add it to the output
X Discard: Pop top value and discard it
^ Repeat: Pop two values amount and value, push value amount of times, if amount is a string it will be the length of the string
S String Converter: Pop top value, if the value is a string than push value, if value is a number push the string representation of value
N String Split: Pop top value, if the value is a number than push value, if the value is a string than for each character in value push the according unicode number
> Skip: Pop two values amount and value, if value is true than skip the next amount of instructions
. Char Input: Read a char from the user and push it onto the stack
_ String Input: Read a string (terminated by enter) from the user and push it onto the stack
: Number Input: Read a number (terminated by enter) from the user and push it onto the stack
v Reverse: pop a value amount, than pop amount of values and push them back in reverse, if amount is a string, amount will be the length of this string
D Output remove: Pop a value and remove that many characters from the output and push the removed characters onto the stack as a string, if value is a string it will be the length of that string
C Clear Output
T Type checkt: pop a value, if the value is a string push 1, otherwise 0
L Length: pop a value, than push the length of that value
? Random: push a random number between 0 and 1
° Mathematical FLOOR: pop a value, turn value into the biggest integer that is less than value and push value, string will produce N/A
l Stack Size: pushes the length of the stack (pushed element excluded)

Examples

Hello World

Hello World!

Truth Machine

$.~1>#end;;#loop;1$#loop;;#end;0

Cat Program

#start;$.,#start;;

99 Bottles of Beer

$99 3^;#songStart;$,; bottles of beer on the wall.
$,; bottles of beer.
Take one down, pass it around,
$1 - 5^1=!>#songStart;;1 bottle of beer on the wall.
1 bottle of beer.

Number Guessung Game (1-3)

Number Guessing Game:#start;
Enter a number (1-3): $?3*°1+3^:=1>#true;#false;;
#false;
Incorrect! Number: $,#start;;
#true;
Correct!$#start;;

Calculator

Calculator:
Enter number 1: $:;
Enter number 2: $:;
Enter operator: (+-*/%): $_ 2^ "+"=3>X+#out; 2^ "-"=3>X-#out; 2^ "/"=3>X/#out; 2^ "*"=3>X*#out; 2^ "%"=3>X%#out;;
Invalid Operator! $#end;;
#out;
$,;
#end;

Random Entry Selector

Random Selector:
- Enter the words you want to choose from
- To finish entering the words press enter without entering anything
- see the result
#entry;Enter a Word: $_2^"\n",!1>#entry;X1D;#select;
$?l * ° v2^,#select;;

FizzBuzz

Fizz Buzz:
Enter count: $:0;#loop;
$1+ 2^ lv 2^ ',lv1DN=1-!1>#calc;#end;;
#calc;$4^ 3% 2^ 3v 5% 2^ 3v | 1> #fizzBuzz; 1> #buzz; 1> #fizz; #print;;
#fizzBuzz;$XX X"FizzBuzz" #print;;
#buzz;$X X"Buzz" #print;;
#fizz;$X"Fizz" #print;;
#print;$,#loop;;
#end;