ThonkLang
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