esolang

bruh():bruh()

Nothing but functions. Even a loop is a function that calls itself.

None1, 2023 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: A

The idea

None1 made bruh():bruh() in 2023. A program is a list of one-line functions on whole numbers that never go below 0. There are no variables, no statements and no loops. The entry point is bruh(), so the shortest infinite loop is the name of the language itself.

Read the story

A function may only call the functions defined above it, and itself. The one way to choose is if, which gets the IDs of two functions and calls one of them. Every function gets a random 64-bit ID when it is defined, and a bare function name stands for that number.

The machine

A line name(x,y):expression defines a function. Spaces and tabs are ignored, even inside names, and ; starts a comment.

FunctionDoes
in() inc()Read a number or a character; 0 at the end of the input
out(x) outc(x)Print x and a line feed, or the character x; give back x
add sub mul div modArithmetic on unbounded numbers; sub stops at 0
0() to 9(), a() to f()The numbers 0 to 15
if(a,b,c,...)Call the function with ID b if a is not 0, else ID c, with the rest as arguments

The specification makes the IDs random on every run. This implementation takes them from a fixed sequence, so a program always gives the same result.

Example

The truth machine picks a function with if.
Expected: 7

The truth machine picks a function with if. On 0 it calls func2, which prints 0 once. On 1, func prints 1 and calls itself forever.

Expected: 0

The factorial ends its recursion with if. sub(x,1()) is 0 when x is 1, and then one gives 1.

Expected: 120

The Hello, world! program defines 14 functions, from f13 up to f0, and builds every character out of 1s. The H alone is 72 of them, nested 71 deep in add.

Patterns it teaches

  • Code as data; a function travels as a number and runs through if.

Further

Functional paradigm

Write your own in Run Convert a program from bruh():bruh()

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: bruh-bruh.

Command line

shib run bruh-bruh -e 'bruh():out(add(in(),in()))' --input '3
4'
shib manual bruh-bruh

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/bruh-bruh.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org