ThonkLang

From Esolang
(Redirected from Thonklang)
Jump to navigation Jump to search

ThonkLang is an esoteric programming language that uses emojis for control flow and features a unique "1 is true, everything else is false" boolean system. It combines functional programming concepts with emoji-based syntax to create a playful yet capable programming environment.

Computational model

ThonkLang is based on a functional programming model with lambda expressions, control flow statements, and loops. It features a unique boolean system where 1 is considered true and any other value is considered false.

Etymology

The language's name combines "Thonk" (internet slang for the thinking face emoji πŸ€”) with "Lang" (short for language). This references the language's primary control flow operator πŸ€”, which serves as the if-statement keyword.

Language description

ThonkLang programs consist of expressions that can include:

  • Lambda function definitions
  • If-else statements using πŸ€” (if) and πŸ˜… (else)
  • While and for loops
  • Basic arithmetic operations (+, -, *, /)
  • Variable assignments
  • Function calls

Control Flow

The language uses emoji-based control flow:

  • πŸ€” serves as the "if" keyword
  • πŸ˜… serves as the "else" keyword
  • Any expression that evaluates to 1 is considered true
  • Any other value is considered false

Functions

Functions are defined using the lambda syntax:

lambda name,param1,param2: { body }

Sample programs

Truth Machine

The following implements a truth machine in ThonkLang:

truth = lambda n: {
    πŸ€” n {
        # If input is 1, enter infinite loop
        while 1 {
            print(1);
        };
    } πŸ˜… {
        # If input is 0, print once and terminate
        print(0);
    };
};

Prime Number Checker

This program checks if a number is prime:

is_divisible = lambda n,d: πŸ€” n - ((n/d) * d) + 1 1 πŸ˜… 0;

is_prime = lambda n: {
    result = 1;
    πŸ€” n 0 πŸ˜… {
        for i in range(n-2) {
            d = i + 2;
            πŸ€” is_divisible(n,d) {
                result = 0;
            } πŸ˜… {
                result = result;
            };
        };
    };
    result
};

Prime Number Generator

This program finds all prime numbers up to a given value:

find_primes = lambda n: {
    for i in range(n-1) {
        num = i + 2;
        πŸ€” is_prime(num) {
            print(num);
        } πŸ˜… 0;
    };
};

Computational class

ThonkLang is Turing-complete, supporting:

  • Conditional branching (through πŸ€”/πŸ˜…)
  • Loops (while and for)
  • Variable assignment
  • Function definitions and calls
  • Basic arithmetic operations

Implementation

ThonkLang is implemented in Python using the Lark parser generator. The implementation consists of:

  • A lexer/parser for the language grammar
  • An interpreter that executes the parsed syntax tree
  • Support for nested scopes and variable binding
  • Built-in functions for basic I/O operations

External resources