From Esolang
Jump to navigation Jump to search

Triangularity is a stack-based esoteric programming language created in early 2018 by PPCG user Mr. Xcoder.

Language Description

Any valid Triangularity program must have a padding made out of dots, laid out in 2 triangles. That is, the Kth line in the program (counting from the bottom upwards) must have K - 1 dots on both sides, and each line of a program must consist of exactly 2L - 1 characters (including the dots), where L is the number of lines in the program. Therefore, the character count of a program in this language must be listed in OEIS A056220.


! – Logical negation. The falsy values are 0, 0.0, 0j, "" (the empty string), [], {}, (), None, False, set() (the empty set).
" – Begins and ends a string literal. Note that the whole string must be on a single line of code.
) – Push a 0 onto the stack.
0123456789 – All these characters take the previous stack entry, multiply it by 10 and add their decimal digit value.
+ – Addition.
/ – Division.
=>< – Comparison functions.
@ – Increment the top of the stack (add 1 to its value).
^ – Exponentiation.
_ – Negative. Multiplies the top of the stack by -1.
` – Cast to string.
C – Counts the number of occurrences of an element in a sequence (either string or list)
E – Evaluate. eval() in Python.
I – Input at that index (modular, 0-based).
J – Join a sequence with a certain separator.
L – Length.
O – Sort.
R – Reverse.
c – Character from ASCII value.
d – Positive divisors.
e – Dump the contents of a sequence separately onto the stack.
f – Cast to int. Trims decimals.
h – Retrieves the first N elements of a sequence.
i – Reads all STDIN and returns a list of lines.
l – Return the 0-based indices in a sequence at which a certain element occurs.
m – Retrieve the element at index N (0-based) into a sequence.
o – Character to ASCII value.
p – Primality test.
r – Range (half-inclusive).
t – Trims the first N elements of a sequence.
u – Sum.
w – Wrap into a singleton list.

Stack Manipulation

D – Duplicate. Push two copies of the argument.
P – Pop. Discards the top of the stack.
W – Wrap the whole stack into a list.
s – Swap the top two stack entries.


There are two operators in Triangularity: Map and Filter. The former is denoted by the character M and is closed with }, and it lets you iterate over a sequence and runs a set of commands on a separate stack, for each element of that collection. The latter does the same, but instead of returning the results of the mapping, it returns the elements that yield a truthy value when ran through the given block of code. It is denoted by the character F and is closed using {.


"Hello, World!"

The classic "Hello, World!" program looks like this:

....... .......
......   ......
.....     .....
....       ....
...         ...
..           ..
.             .
"Hello, World!"

That's because the whole string must be on a single line of code. The shortest known program for this task is, however:

.... ....
."o, Wo".

Which uses multiple strings concatenated together, to avoid / minimise the one-line problem.

Automatic padding adder


This is a program that adds padding to a single-line string given as input, such that the output is a validly-structured Triangularity program. Disclaimer: This doesn't handle string literals.

Online Interpreter

Thanks to Dennis, there is a free online interpreter available at Try it online!