Drib is an esoteric programming language that represents every number as a string. Arithmetic and logic are performed via built-in functions operating on those string values, offering a quirky, mind-bending take on computation. This project includes a lightweight interpreter with a REPL, file execution, and optional Python code generation.
A variable is a named storage location that holds a value you can read and update while your program runs.
In Drib, variables can store strings, booleans (true/false), or nil. Numbers are
represented as strings, and math is done via built-ins (e.g.,
add, sub).
val message = "Hello";println(message); // prints: Hellomessage = "Hello, Drib!";println(message); // prints: Hello, Drib!
Use when(condition) to run code only when
the condition evaluates to true, and add an
optional otherwise block for the false case. Conditions
are boolean expressions, typically built with built-ins like eqs, gt, and lt. Parentheses are
required after when, and blocks use braces.
val x = "12";when(gt(x, "10")) { println("bigger");} otherwise { println("smaller or equal");}
Built-in functions are core utilities provided by a
language/runtime, available without importing anything
(e.g.,
print, len, abs).
Sum two numeric strings; returns number string.
val r = add("2", "3");println(r); // "5" Difference of two numeric strings.
val r = sub("10", "4");println(r); // "6" Product of two numeric strings.
val r = mul("6", "7");println(r); // "42" Division; int division if both ints, handles 0/Infinity/NaN.
println(div("7", "2")); // "3" if ints, "3.5" if any
floatprintln(div("7", "0")); // "Infinity" Exponentiation a^b on numeric strings.
println(pow("2", "8")); // "256" Remainder a % b for numeric strings.
println(mod("17", "5")); // "2" Numeric greater-than; returns boolean.
println(gt("3", "2")); // True Numeric less-than; returns boolean.
println(lt("2", "3")); // True Numeric greater-or-equal; returns boolean.
println(geq("3", "3")); // True Numeric less-or-equal; returns boolean.
println(leq("2", "3")); // True Equality; numeric if possible else string compare.
println(eqs("2", "2")); // True Logical AND of two booleans.
println(et(gt("3", "2"), lt("1", "5"))); // True Logical OR of two booleans.
println(aut(lt("3", "2"), gt("1", "0"))); // True Logical NOT of a boolean.
println(not(eqs("1", "2"))); // True Print without trailing newline.
print("Hello");println(" world!"); // same line output Print with trailing newline.
println("Hello, Drib!"); Create a list from arguments.
val a = list("1", "2", "3");println(a); Get element at index from list.
val a = list("10", "20", "30");println(get(a, "1")); // "20" Set element at index in list.
val a = list("10", "20", "30");set(a, "1", "42");println(a); // "10","42","30" Length of list; returns number string.
val a = list("a", "b", "c");println(size(a)); // "3" Load image as 2D array of RGB string triples.
val img = imread("./examples/assets/lenna.png");println(size(img), "x", size(get(img, "0"))); // height
x width Save 2D array of RGB ints to an image file.
val img = zeros("2", "2"); // 2x2 blackimwrite(img, "./out.png");println("saved ./out.png"); Create WxH black image (RGB "0" strings).
val z = zeros("3", "2"); // width=3, height=2println(size(z), "x", size(get(z, "0"))); // "2 x 3" Convert numeric to int string; handles Infinity/NaN.
println(int("3.7")); // "3"println(int("Infinity")); // "Infinity" Square root; returns number string or "NaN".
println(sqrt("9")); // "3.0"println(sqrt("-1")); // "NaN" Absolute value; returns number string; handles Infinity/NaN.
println(abs("-42")); // "42"println(abs("Infinity")); // "Infinity"