CATASTROPHICA

From Esolang
Jump to navigation Jump to search

CATASTROPHICA is an esolang created by User:Random.esotera. It is inspired by brainfuck, uses digit-based manipulation to define values and positional referencing. It was named CATASTROPHICA because it resembles a catastrophic report card. Galang!! is a much more refined language also created by User:Random.esotera that takes a lot of concepts and inspiration from CATASTROPHICA.

Commands

Command Definition
{} Reference instances. The amount of Ds placed inside of it determines what is referenced. For example, B{D} represents the first variable created in a CATASTROPHICA program. If there are more Ds than created instances, return the null value.
A Store code. Code wrapped in 2 As and () will be stored as a sample and will not be executed. Use {} to reference samples. These samples get directly inserted into the program.
B Define a variable and set it equal to the value after B (could be a number, could be another variable). Just B = define a variable equal to null. If a variable is referenced before B, set the variable equal to the value after B.
C Move one digit left. When first used, it defaults to the unit's digit. Just using C creates value 0. If a variable is referenced before C, Cs and Ds can be used to directly manipulate the digits of that variable.
D Increment by 1. For every use of C, use 1-9 Ds. Will not increment if C is not used and digit is not specified. Instead, if a variable referenced before D, add the value after D to that variable.
E When used after referencing a variable with {}, duplicate that variable's position and place it at the last position in the instance order.
O Outputs a number.
! Alters certain commands. Full list below.
[] Create loops. Loops run as long as the variable referenced or defined before it is > 0.
() Changes the order commands run in, like in normal mathematics and most other programming languages.
: Starts a statement.
; Ends a statement.

Statements are any of the following:

  • :A(...)A;
  • :BC...;
  • :X{}...; If 2 X{}s are nested inside of each other, place ()s around the inner X{}s

Alternate commands

Command Definition
!{} References the last instances. For example, !{DD} refers to the second last instance.
!C Moves one digit right.
!D Subtracts when a variable is referenced before it.
!O Outputs 1 character using ASCII.
![] Runs as long as the variable referenced or defined before it is < 0.

Examples

Truth machine

[]s are essentially built in truth machines:

:BC;:B[OB{D}];

Factorial

:BCDDDDD;:BC;:BC;:A(:B!{D}[:B!{DD}DB!{DDD};:B!{D}!DCD;]);A;:B{D}[:B!{DDD}E;:!B{DD}E;:BCB(:B![DDD}!DCD;);:A{D};:B!{DDD}!DCD;];
:OB!{DD};

Outputs 5! = 120

Fibonacci sequence

:BCDDDDDDD;:BC;:BCD;:BC;:B{D}[:B{DDDD}B(:B{DD}D(:B{DDD};););:B{DD}B(:B{DDD};);:B{DDD}B(:B{DDDD};);:B{D}!DCD;];:OB{DDDD};

Outputs the 7th term of the Fibonacci sequence = 8, if we count the first 0.

Other

If-else statement along with generalization using A and E (this concept is applicable to everything else too.):

:BC;:B(CD!D(:B{D};));:A(:B!{D}[<if true>];:B!{DD}[<if false>];)A;:B{D}E;:B{DD}E;:A{D};

Less than operation:

:BCDDDD;:BCDDDDDD;:BC;:B{D}[:B{D}!DCD;:B{DD}!DCD;];:B{DD}[:BC{DDD}BCD;];

Outputs 1 if a < b and 0 if a > b.