Unlease the madness with

ChaosLang

Created to match the madness of Programmers

Made by © AmAn SonwAni at CMxLabs

Interactive Playground

Test the chaos below

Tutorial

Building Your First Chaos Program

Let’s create a simple program with both Normal and Crazy Modes:

Code

kaboom main() {
    glitch("Starting...");
    crash x = 10;
    glitch(x);
    unleashchaos;
    glitch("Chaos unleashed!");
    glitch(x); // Random tweak
}

Output

Universe 0: Starting...
Universe 0: 10
Universe 0: Chaos unleashed!
Universe 0: 12 (example with random tweak)

Note

Declare variables with crash, output with glitch, and switch to Crazy Mode with unleashchaos.

Documentation

Introduction

ChaosLang is a programming language designed to blend structured programming with chaotic behavior. It operates in two distinct modes:

  • Normal Mode: Provides predictable execution for standard programming tasks.
  • Crazy Mode: Introduces chaotic behavior such as random number tweaks, array shuffling, and visual effects on a canvas.

Reference Guide

Keywords

  • kaboom: Defines a function.
  • crash: Declares a variable.
  • glitch: Prints output.
  • if: Conditional statement.
  • return: Returns a value from a function.
  • meltdown: While loop.
  • explode: Breaks out of loops or functions.
  • chaosfor: For loop with start, end, and step.
  • chaosforeach: For-each loop for arrays.
  • in: Used in chaosforeach loops.
  • unleashchaos: Activates Crazy Mode.
  • mutate: Redefines a function.
  • chaoscall: Randomly calls a function (Crazy Mode).
  • rewind: Reverts program state.
  • corrupt: Randomly modifies code (Crazy Mode).
  • multiverse: Runs in parallel universes (Crazy Mode).

Operators

  • Arithmetic: +, -, *, /, %, ^
  • Comparison: >, <, = (flipped in Crazy Mode)
  • Quantum: | (for quantum variables)

Array Methods

  • push(value): Adds a value to the end.
  • pop(): Removes and returns the last value.
  • shift(): Removes and returns the first value.
  • unshift(value): Adds a value to the beginning.
  • length: Property to get the array length.

Getting Started

Hello, ChaosLang!

Every ChaosLang program starts with a main function defined using the kaboom keyword.

Code

kaboom main() {
    glitch("Hello, ChaosLang!");
}

Output

Universe 0: Hello, ChaosLang!

Note

Simple output in Normal Mode.

Activating Crazy Mode

Use unleashchaos to enable Crazy Mode.

Code

kaboom main() {
    glitch("Starting in Normal Mode...");
    unleashchaos;
    glitch("Now in Crazy Mode!");
}

Output

Universe 0: Starting in Normal Mode...
Universe 0: Now in Crazy Mode!

Note

Random shapes appear on the canvas in Crazy Mode.

Syntax & Features

Variables

Standard Variables

Code

kaboom main() {
    crash x = 42;
    glitch(x);
}

Output

Universe 0: 42

Note

Basic variable declaration.

Quantum Variables

Code

kaboom main() {
    crash x = 1 | 2 | 3;
    glitch(x);
    glitch(x);
}

Output

Universe 0: 2
Universe 0: 3 (example)

Note

Random value chosen each access.

Output

Code

kaboom main() {
    glitch("Chaos is here!");
    crash x = 10;
    glitch(x);
}

Output

Universe 0: Chaos is here!
Universe 0: 10

Note

Prints strings or variables.

Functions

Code

kaboom add(a, b) {
    return a + b;
}

kaboom main() {
    crash result = add(5, 3);
    glitch(result);
}

Output

Universe 0: 8

Note

Functions with parameters and return.

Operators

Code

kaboom main() {
    crash x = 5 + 3 * 2;
    glitch(x);
    
}

Output

Universe 0: 11
Universe 0: true
Universe 0: false

Note

Comparison flips in Crazy Mode.

Conditionals

Code

kaboom main() {
    crash x = 10;
    if (x > 5) {
        glitch("x is greater than 5");
    }
}

Output

Universe 0: x is greater than 5

Note

Basic conditional logic.

Loops

chaosfor Loop

Code

kaboom main() {
    chaosfor (i = 0; 5; 1) {
        glitch(i);
    }
}

Output

Universe 0: 0
Universe 0: 1
Universe 0: 2
Universe 0: 3
Universe 0: 4

Note

Iterates with step value.

chaosforeach Loop

Code

kaboom main() {
    crash arr = [1, 2, 3];
    chaosforeach (item in arr) {
        glitch(item);
    }
}

Output

Universe 0: 1
Universe 0: 2
Universe 0: 3

Note

Iterates over arrays.

meltdown Loop

Code

kaboom main() {
    crash x = 0;
    meltdown (x < 3) {
        glitch(x);
        crash x = x + 1;
    }
}

Output

Universe 0: 0
Universe 0: 1
Universe 0: 2

Note

While loop equivalent.

Arrays

Array Declaration and Access

Code

kaboom main() {
    crash arr = [10, 20, 30];
    glitch(arr[1]);
}

Output

Universe 0: 20

Note

Access elements with indices.

Array Methods

Code

kaboom main() {
    crash arr = [1, 2];
    arr.push(3);
    glitch(arr);
    crash popped = arr.pop();
    glitch(popped);
}

Output

Universe 0: [1, 2, 3]
Universe 0: 3

Note

Modify arrays with methods.

Array Properties

Code

kaboom main() {
    crash arr = [1, 2, 3];
    glitch(arr.length);
}

Output

Universe 0: 3

Note

Get array length.

Crazy Mode Features

unleashchaos

Code

kaboom main() {
    crash x = 5;
    glitch(x);
    unleashchaos;
    glitch(x);
}

Output

Universe 0: 5
Universe 0: 7 (example)

Note

Tweaks numbers and shuffles arrays.

chaoscall

Code

kaboom sayHello() {
    glitch("Hello!");
}

kaboom main() {
    unleashchaos;
    chaoscall;
}

Output

Universe 0: Hello! (if chosen)

Note

Random function call in Crazy Mode.

corrupt

Code

kaboom main() {
    crash x = 5 + 3;
    glitch(x);
    unleashchaos;
    corrupt;
}

Output

Universe 0: 8
Code corrupted!
Universe 0: 53 (example)

Note

Randomly modifies code.

multiverse

Code

kaboom main() {
    crash x = 5;
    unleashchaos;
    multiverse;
    glitch(x);
}

Output

Universe 1: 3
Universe 2: 7 (example)

Note

Runs in parallel universes.

Function Mutation

Code

kaboom greet() {
    glitch("Hello!");
}

kaboom main() {
    greet();
    mutate greet() = {
        glitch("Hi!");
    };
    greet();
}

Output

Universe 0: Hello!
Universe 0: Hi!

Note

Redefines a function.

Control Flow

explode

Code

kaboom main() {
    chaosfor (i = 0; 5; 1) {
        glitch(i);
        if (i = 2) {
            explode;
        }
    }
}

Output

Universe 0: 0
Universe 0: 1
Universe 0: 2

Note

Breaks out of loops.

return

Code

kaboom square(x) {
    return x * x;
}

kaboom main() {
    crash result = square(4);
    glitch(result);
}

Output

Universe 0: 16

Note

Returns a value.

Error Handling

Code

kaboom main() {
    panic("Something went wrong!");
}

Output

Chaos unleashed: Something went wrong! at line 2

Note

Throws an error.

Time Travel

Code

kaboom main() {
    crash x = 1;
    glitch(x);
    crash x = 2;
    glitch(x);
    rewind 1;
}

Output

Universe 0: 1
Universe 0: 2
Universe 0: 1

Note

Reverts state by steps.

Examples

Fibonacci

Code

kaboom fibonacci(n) {
crash a = 0;
crash b = 1;
chaosfor (i = 0; n; 1) {
    glitch(a);
    crash temp = a + b;
    crash a = b;
    crash b = temp;
}
}

kaboom main() {
    fibonacci(6);
}

Output

Universe 0: 0

Universe 0: 1

Universe 0: 1

Universe 0: 2

Universe 0: 3

Universe 0: 5

Note

Fibonacci series generation.

Crazy Array Shuffle

Code

kaboom main() {
    crash arr = [1, 2, 3];
    glitch(arr);
    unleashchaos;
    glitch(arr); // Shuffled!
}

Output

Universe 0: [1, 2, 3]
Universe 0: [3, 1, 2] (example)

Note

Array shuffling in Crazy Mode.

DiceRoll with Quantum VARs

Code

kaboom rollDice() {
    crash roll = 1 | 2 | 3 | 4 | 5 | 6;
    glitch("You rolled a " + roll + "!");
}

kaboom main() {
    rollDice();
    rollDice();
}

Output

Universe 0: You rolled a 2!
Universe 0: You rolled a 3!

Note

Rolling Dice via Quantum Variables.

Contact Me

For inquiries, reach out to me at